首页 文章

电报Bot欢迎问候消息

提问于
浏览
0

“如何使用Bot在电报中发送欢迎致辞信息”?实际上,我在电报中创建了新的机器人 . 现在我想,当新用户启动我的机器人时,我的机器人会向他发送欢迎问候消息?有可能使用“getupdates”方法或我应该使用“webhooks”吗?请指导我 .

我创建了一个像@mak_tech_bot这样的机器人 . 并加入我的其他电报,但它不发送任何欢迎信息 . 我也使用/命令 .

我也在localhost中尝试过一个例子

<?php
ini_set('error_reporting',E_ALL);
$botToken = "TOKEN";
$website = "https://api.telegram.org/bot".$botToken;

$update = file_get_contents('php://input');
$update = json_decode($update,TRUE);

$chatId = $update["message"]["chat"]["id"];
$message = $update["message"]["text"];

switch($message){
    case "/test":
        sendMessage($chatId,"test123");
        break;
    case "/hi":
        sendMessage($chatId,"Hello123");
        break;
    default:
        sendMessage($chatId,"default");
}

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

1 回答

  • 0

    当您单击 START 按钮时,您将向机器人发送 /start 命令,只需将 case '/start': 添加到您的代码中即可发送问候消息 .

相关问题