电报机器人群中不需要的自我报价

时间:2018-06-25 00:33:00

标签: php keyboard bots telegram

我刚刚为公会的同伴们开始了一个小项目。 我的编码经验为零,但大量的指南指南却给出了一些结果。 在私人聊天,键盘操作和命令中,一切都进行得很好。 现在,我将这个bot放在了行会超级组中,命令可以正常工作,但是如果我按“ Conigli”按钮,则附上的图片将进行解释,第一次一切都很好,并且我得到了正确的答案,那么该bot就开始自我报价。 正如我说的,我的经验为零,所以我不知道问题出在哪里,因此我需要一些帮助。 谢谢你,我的英语不好,我也正在努力:)

<?php

    $botToken = "mytoken";
    $website = "https://api.telegram.org/bot".$botToken;
    $FilejSon = file_get_contents("php://input");
    $FilejSon = json_decode($FilejSon, TRUE);
    $FirstName = $FilejSon["message"]["chat"]["first_name"];
    $UserChatId = $FilejSon["message"]["chat"]["id"];
    $Message = $FilejSon["message"]["text"];
    $a = ['Buongiorno', 'Buongiorno Cavaliere!', 'Bentrovato compagno!'];

    switch ($Message)
    {
        case '/vai':
            $msg = "Ciao $GLOBALS[FirstName]!";
            showKeyboard($UserChatId, $msg);
            break;

        case 'Buongiorno':
            $msg = $a[mt_rand(0, count($a) - 1)];
            sendMessage($UserChatId, $msg);
            break;

        case " Conigli ": // This is the same text inside a Keyboard
            $msg = "La difficoltà EX dei conigli è disponibile nei seguenti orari: 00:00/05:00/13:00/16:00";
            showKeyboard($UserChatId, $msg);
            break;

        case "Inline Keyboard":
            $msg = "Abracadabra and inline keyboard will appear!";
            inlineKeyboard($UserChatId, $msg);
            break;

        case "Remove Keyboard":
            $msg = "Abracadabra and keyboard will disappear!";
            removeKeyboard($UserChatId, $msg);
            break;

        default:
            $msg = "Unknown Command! So sorry ;(";
            sendMessage($ChatId, $msg);
            break;
    } 


    function sendMessage($chat_id, $text)
    {
        $url = $GLOBALS[website]."/sendMessage?chat_id=".$chat_id."&text=".urlencode($text);
        file_get_contents($url);
    }

    function showKeyboard($chat_id, $text)
    {
        $jSonCodeKeyboard = '&reply_markup={"keyboard":[["%20Conigli%20"]],"resize_keyboard":true,"one_time_keyboard":false}';
        $url = $GLOBALS[website]."/sendMessage?chat_id=".$chat_id."&text=".urlencode($text).$jSonCodeKeyboard;
        file_get_contents($url);
    }

?>

Chat Image

0 个答案:

没有答案