【发布时间】:2017-04-11 05:02:02
【问题描述】:
帮我为电报机器人(php)创建键盘(是/否)
【问题讨论】:
-
SO 不是要求人们编写代码的地方!到现在为止你自己做了什么?请阅读帮助中心的这两篇文章:How do I ask a good question? 和 How to create a Minimal, Complete, and Verifiable example
标签: keyboard telegram-bot
帮我为电报机器人(php)创建键盘(是/否)
【问题讨论】:
标签: keyboard telegram-bot
我不知道 PHP,但棘手的部分通常是键盘部分,它是一个数组数组。调用 sendMessage 并传递类似于以下 json 的内容:
{
chat_id: 12345678,
text: "Hello, do you like ice cream?",
reply_markup: {
keyboard: [
[{text: "Yes"}],
[{text: "No"}]
]
}
}
将 12345678 替换为您的聊天 ID。
【讨论】:
首先获取更新并将它们保存到$update 然后ReplyKeyboardMarkup 使用此方法:
if ($update->message->text == '/start') {
$name = $update->message->chat->first_name;
bot('sendMessage',[
'chat_id' => $update->message->chat->id,
'text'=>'Your Test',
'resize_keyboard'=>true,
'reply_markup'=>json_encode([
'keyboard'=>[
[
['text'=>'Num1'],['text'=>'Num2']
],
[
['text'=>'Num2']
],
]
])
]);
}
对于内联键盘,您应该使用此方法发送:
'reply_markup'=>json_encode([
'inline_keyboard'=>[
[
['text'=>'Num1'],['text'=>'Num2']
],
[
['text'=>'Num3']
],
]
])
]);
}
请记住,bot 函数有 2 个参数,它们使用 curl 向电报 api 发送和接收数据。
【讨论】: