“如何在 Telegram 中使用 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);
}
?>