2017-08-30 29 views
0

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

我创建了一个像@mak_tech_bot的机器人。并与我的其他电报会面,但它不发送任何欢迎消息。我也使用/命令。

我也试过一个例子在本地主机

<?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); 
} 
?> 

回答

0

当您单击START按钮,您将发送/start命令的机器人,只需添加case '/start':到你的代码发送问候信息。

+0

谢谢,但它可能没有webhook方法,我想测试它在我的本地主机,所以这可能吗? – mayank

+0

没有webhook是可能的。但是,你可以使用[getUpdates](https://core.telegram.org/bots/api#getupdates)。你需要有一些机制来知道是否与你的机器人进行了任何交互。使用webhooks电报会尽快发布更新。使用getUpdates你必须实现你自己的轮询机制。 – newsha