gpt4 book ai didi

python - 如何使用 LINE 聊天机器人 "reply_message function"回复多条消息给用户

转载 作者:行者123 更新时间:2023-11-28 19:01:17 25 4
gpt4 key购买 nike

我正在尝试使用 reply_message 函数向用户发回多条消息,但我在那里遇到了一些麻烦。

在官方SDK文档中我们知道如何使用reply_message函数的例子是:

line_bot_api.reply_message(event.reply_token, TextSendMessage(text = "123"))

如果用户发送消息,Line bot 将显示消息“123”。

但是官方github上说“reply_message”函数可以发送同时显示 5 条消息。

官方github截图

official github link

另外,文档说请求主体应该发回两个参数:replyToken 和消息(请看截图) offical reply_message SDK document link

the SDK document of reply message function screenshot

表示将消息对象数组放入消息参数中。消息对象数组如下所示: the SDK document of message object example link

the SDK document of message object screenshot

另一种方式我发现有人用PHP实现就是用这个函数。

PHP implement method example

但是我仍然找不到如何使用Python在reply_message函数中发送多条消息的解决方案..

我尝试用 Python 编写的代码是:

line_bot_api.reply_message({'reply_token' : event.reply_token, 'messages' : [{'type' : 'text', 'text' : '123'}]})

错误信息是:

TypeError:reply_message() 缺少 1 个必需的位置参数:'messages'

错误消息日志

我试过另一种方式放参数,还是不行

line_bot_api.reply_message(reply_token = event.reply_token, messages = [{'type' : 'text', 'text' : '123'}])

错误信息是:

AttributeError: 'dict' object has no attribute 'as_json_dict'

这在 Python 中如何完成?

最佳答案

最后,我找到了解决方案。

例子如下:

line_bot_api.reply_message(event.reply_token, [TextSendMessage(text= reply_text), TextSendMessage(text= reply_text1)])

关于python - 如何使用 LINE 聊天机器人 "reply_message function"回复多条消息给用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52385079/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com