function talk($chat_id, $text) { apiRequestWebhook("sendMessage", array('chat_id' => $chat_id, "text" => $text)); }
function processMessage($message) { // process incoming message $message_id = $message['message_id']; $chat_id = $message['chat']['id']; if (isset($message['text'])) { // incoming text message $text = $message['text']; if (strpos($text, "/start") === 0) { apiRequestJson("sendMessage", array('chat_id' => $chat_id, "text" => 'Hello', 'reply_markup' => array('keyboard' => array(array('Hello', 'Hi')), 'one_time_keyboard' => true, 'resize_keyboard' => true))); } else { if ($text === "Hello" || $text === "Hi") { apiRequest("sendMessage", array('chat_id' => $chat_id, "text" => 'Nice to meet you')); } else { if (strpos($text, "/stop") === 0) { // stop now } else { apiRequestWebhook("sendMessage", array('chat_id' => $chat_id, "reply_to_message_id" => $message_id, "text" => 'Cool')); } } } } else { apiRequest("sendMessage", array('chat_id' => $chat_id, "text" => 'I understand only text messages')); } }
function processMessage($message) { // process incoming message $message_id = $message['message_id']; $from = $message['from']['id']; $chat_id = $message['chat']['id']; if (isset($message['text'])) { // incoming text message $text = $message['text']; /*if (strpos($text, "/start") === 0) { apiRequestJson("sendMessage", array('chat_id' => $chat_id, "text" => 'Hello', 'reply_markup' => array( 'keyboard' => array(array('Hello', 'Hi')), 'one_time_keyboard' => true, 'resize_keyboard' => true))); } else */ if ($text === "Hello" || $text === "Hi") { apiRequest("sendMessage", array('chat_id' => $chat_id, "text" => 'ohi')); } else { if (strpos($text, "/stop") === 0) { // stop now } else { if ($text[0] == '/') { $answer = ""; if (strpos($text, "/chat_id") === 0) { $answer = 'Current chat id is: ' . $chat_id; } else { if (strpos($text, "/me") === 0) { $answer = 'Your id: ' . $from; } else { if (strpos($text, "/send") === 0) { $param = substr($text, strlen("/send")); $answer = 'Sending <' . $param . '>'; sendToWebChat(array('ipod_id' => urlencode($from), "msg" => urlencode($param))); } else { $answer = 'Sorry, I don\\t know such command. Now I know only `/chat_id`, and also can reply to `Hi` or `Hello`'; } } } apiRequestWebhook("sendMessage", array('chat_id' => $chat_id, "reply_to_message_id" => $message_id, "text" => $answer)); } } } } else { apiRequest("sendMessage", array('chat_id' => $chat_id, "text" => 'I understand only text messages')); } }