2016-09-27 9 views
0

テレグラムボットを作成しました。テレグラムボットが特定のコマンドを受け取ったときにexecコマンドを使ってindex.phpをバックグラウンドで別のphp(worker.php)を実行させたいと考えています。メッセージをユーザから受信する。 可能であれば、私はHeroku exampleの場合と比較して簡単にしたいと思います。 worker.phpコードは、今度はindex.phpがやっているように電文チャットにもメッセージを送信できるはずです。 この例では、引数のパス(特にチャット情報)をチェックするように設定しましたが、そうではありません。誰か助けてください、これはコードですか?/dev/null &コマンドが "exec"コマンドで設定されていないため、現時点では実際にバックグラウンドで実行されていません。Heroku、php、exec and telegram bot

"送信者" 側:

$update_j = json_encode($update); 

$response = $client->sendMessage([ 
      'chat_id' => $update->message->chat->id, 
      'text' => $update_j 
]); 

exec('php /app/worker.php?update=' . $update_j, $out, $ret_v); 

$ update_jの出力が正しいよう:

<?php 


require 'vendor/autoload.php'; 
require 'require.php'; 


try { 

$foo = file_get_contents("php://input"); 
$out = json_decode($foo, true); 
$update = $out->{'update'}; 

$response = $client->sendChatAction(['chat_id' => $update->message->chat->id, 'action' => 'typing']); 
$response = $client->sendMessage([ 
      'chat_id' => $update->message->chat->id, 
      'text' => "var_dump = " . var_dump($out) 
]); 


} catch (\Zelenin\Telegram\Bot\NotOkException $e) {} 
:worker.php側

{"update_id":XXXXXXXXX,"message":{"message_id":YYYY,"from":{"id":ZZZZZZZZ,"first_name":"Name"},"chat":{"id":ZZZZZZZZ,"first_name":"Name","type":"private"},"date":WWWWWWWWWWW,"text":"\/runjob","entities":[{"type":"bot_command","offset":0,"length":7}]}} 

を、コードはこれです

$ ret_vの値は1です。私はvar_dump($ out)値を含むメッセージを受け取っていません。

誰かが間違っていることを助けることができますか?おかげさまで sendMessageであなたが今textとして

答えて

0

だからではなく、var_dump()

json_encodejson_encodeを使用することができ、文字列

次のようになります。

文字列json_encode(混合$値[、int型$オプション= 0 [、int $ depth = 512]]
のJSON表現を含む文字列を返します値。あなたのコードのための

更新:

$response = $client->sendMessage([ 
      'chat_id' => $update->message->chat->id, 
      'text' => "var_dump = " . json_encode($out) 
]); 
関連する問題