コード例 #1
0
function talk($chat_id, $text)
{
    apiRequestWebhook("sendMessage", array('chat_id' => $chat_id, "text" => $text));
}
コード例 #2
0
ファイル: Putilych.php プロジェクト: Crackozabra/bots
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'));
    }
}
コード例 #3
0
ファイル: index.php プロジェクト: Shahan/shoutboxMirrorBot
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'));
    }
}