InlineKeyboard 使用请求电报库
InlineKeyboard using requests telegram library
我正尝试在请求 python 库的电报帖子下插入键盘,但我收到此错误:name 'inline_keyboard' is not defined
。我正在关注此文档 https://core.telegram.org/bots/api#inlinekeyboardbutton
我的代码:
def SendMessage(chat_id, text, parse_mode, reply_markup):
"""
:param chat_id integer or string
:param text string max 4096 characters
"""
response = requests.post(url="https://api.telegram.org/botMYTOKENXXX/sendMessage",
data={'chat_id': chat_id, 'text': text, 'parse_mode': 'Html', 'reply_markup': 'array_of_arrays'}).json()
keyboard = inline_keyboard[("text")]
SendMessage("myid", "text" , parse_mode="HTML", reply_markup = keyboard)
inline_keyboard是字典key.You必须在字符串.
中输入
还可以使用 json 库 [= 将 dictionary 转换为 json 11=]
import requests,json
token="YourToken"
def SendMessage(chat_id, text, parse_mode, reply_markup):
data={'chat_id': chat_id, 'text': text, 'parse_mode': parse_mode, 'reply_markup': reply_markup}
return requests.post(url="https://api.telegram.org/bot"+token+"/sendMessage",data=data).json()
keyboard = json.dumps({'inline_keyboard':[[{"text":"hello","callback_data":"clicked"}]]})
SendMessage("myid", "text" , parse_mode="HTML", reply_markup = keyboard)
我正尝试在请求 python 库的电报帖子下插入键盘,但我收到此错误:name 'inline_keyboard' is not defined
。我正在关注此文档 https://core.telegram.org/bots/api#inlinekeyboardbutton
我的代码:
def SendMessage(chat_id, text, parse_mode, reply_markup):
"""
:param chat_id integer or string
:param text string max 4096 characters
"""
response = requests.post(url="https://api.telegram.org/botMYTOKENXXX/sendMessage",
data={'chat_id': chat_id, 'text': text, 'parse_mode': 'Html', 'reply_markup': 'array_of_arrays'}).json()
keyboard = inline_keyboard[("text")]
SendMessage("myid", "text" , parse_mode="HTML", reply_markup = keyboard)
inline_keyboard是字典key.You必须在字符串.
中输入
还可以使用 json 库 [= 将 dictionary 转换为 json 11=]
import requests,json
token="YourToken"
def SendMessage(chat_id, text, parse_mode, reply_markup):
data={'chat_id': chat_id, 'text': text, 'parse_mode': parse_mode, 'reply_markup': reply_markup}
return requests.post(url="https://api.telegram.org/bot"+token+"/sendMessage",data=data).json()
keyboard = json.dumps({'inline_keyboard':[[{"text":"hello","callback_data":"clicked"}]]})
SendMessage("myid", "text" , parse_mode="HTML", reply_markup = keyboard)