Python 3.x 如何从AWS API网关获取电报webhook回调事件?
如何从AWS API网关获取电报webhook回调事件 现在,我使用aws lambda+apigateway创建电报webhook机器人。 我可以正常地通过命令触发机器人。就像/hi->bot返回“hi” 我还尝试使用InLine按钮。 就这样Python 3.x 如何从AWS API网关获取电报webhook回调事件?,python-3.x,aws-lambda,telegram-bot,api-gateway,telegram-webhook,Python 3.x,Aws Lambda,Telegram Bot,Api Gateway,Telegram Webhook,如何从AWS API网关获取电报webhook回调事件 现在,我使用aws lambda+apigateway创建电报webhook机器人。 我可以正常地通过命令触发机器人。就像/hi->bot返回“hi” 我还尝试使用InLine按钮。 就这样 replytext = '{"inline_keyboard": [[{"text": "two", "callback_data": "two"},
replytext = '{"inline_keyboard": [[{"text": "two", "callback_data": "two"}, {"text": "one", "url": "https://yahoo.com/"}], [{"text": "one", "callback_data": "/one"}]]}'
url = URL + "sendMessage?text={}&chat_id={}&reply_markup={}".format(text, chat_id,replytext)
requests.get(url)
我可以使用普通按钮。除此之外,我还可以触发url按钮。
但是我不能触发回调数据按钮
我已经用DynamoDB记录了这个事件。我总是可以得到命令事件。
但是我在dynamoDB中找不到任何回调事件
下面是我的全部代码
=====================
import json
import requests
import boto3
TELE_TOKEN='********'
URL = "https://api.telegram.org/bot{}/".format(TELE_TOKEN)
client = boto3.client('dynamodb')
def send_button_message(text, chat_id):
replytext = '{"inline_keyboard": [[{"text": "two", "callback_data": "two"}, {"text": "one", "url": "https://tw.yahoo.com/"}], [{"text": "one", "callback_data": "/one"}]]}'
url = URL + "sendMessage?text={}&chat_id={}&reply_markup={}".format(text, chat_id,replytext)
requests.get(url)
def send_message(text, chat_id):
url = URL + "sendMessage?text={}&chat_id={}".format(text, chat_id)
requests.get(url)
def lambda_handler(event, context):
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('test')
response = table.put_item(
Item={
'id': str(event)
}
)
request_body = json.loads(event['body'])
chat_id = request_body['message']['chat']['id']
command_arguments = request_body['message']['text'].split()
command = command_arguments[0]
arguments = command_arguments[1:]
try:
callback_data = request_body['update']['callback_query']['from']['id']
send_message('callback_query', chat_id)
except:
callback_data=None
if command =="/hi":
send_button_message('hi', chat_id)
elif command=="/close":
send_message('now_close', chat_id)
elif command=="/other":
send_message('other', chat_id)
else:
send_message("no cmd", chat_id)
return{
'statusCode': 200
}
多谢各位~