【发布时间】:2020-05-30 12:59:09
【问题描述】:
我在 linebot 中的 flex 消息有问题,我正在尝试制作多个 Flex 消息,如轮播模板,我按照示例在阅读文档 here 后制作了两个案例。我在第一个案例中成功了,但是案例 2 不起作用。 顺便说一句,我在 Heroku 中部署了应用程序,在案例 2 中我得到了“status=200”,但没有任何响应。 我应该如何解决问题? 下面是我的代码: 案例一:
if event.message.text == 'test1':
reply_header = {'Content-Type': 'application/json; charset=UTF-8',
'Authorization': 'Bearer ' + 'xxx'}
reply_json = {
"replyToken": event.reply_token,
"messages": [
{
"type": "flex",
"altText": "Flex Message",
"contents": {
"type": "bubble",
"direction": "ltr",
"header": {
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "text",
"text": "Header",
"align": "center"
}
]
},
"hero": {
"type": "image",
"url": "https://developers.line.me/assets/images/services/bot-designer-icon.png",
"size": "full",
"aspectRatio": "1.51:1",
"aspectMode": "fit"
},
"body": {
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "text",
"text": "Body",
"align": "center"
}
]
},
"footer": {
"type": "box",
"layout": "horizontal",
"contents": [
{
"type": "button",
"action": {
"type": "uri",
"label": "Button",
"uri": "https://linecorp.com"
}
}
]
}
}
}
]
}
r = requests.post("https://api.line.me/v2/bot/message/reply", headers=reply_header, json=reply_json)
案例 2:
if event.message.text == 'test2':
reply_header = {'Content-Type': 'application/json; charset=UTF-8',
'Authorization': 'Bearer ' + 'xxx'}
reply_json = {
"replyToken": event.reply_token,
"type": "carousel",
"contents": [
{
"type": "bubble",
"body": {
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "text",
"text": "First bubble"
}
]
}
},
{
"type": "bubble",
"body": {
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "text",
"text": "Second bubble"
}
]
}
}
]
}
r = requests.post("https://api.line.me/v2/bot/message/reply", headers=reply_header, json=reply_json)
【问题讨论】:
标签: python-3.x heroku line-api