How using LINE chat bot "reply_message function" to reply multi-messages to user

Viewed 2387

I'm trying to use reply_message function to send back multi-messages to user, but I got some trouble in there.

In the official SDK document we know how to using the reply_message function example is:

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

And then the Line bot will show the message "123" if user send something messages.

But in the official github it said that "reply_message" function can send 5 messages at same time.

official github Screenshot

official github link

Also, the document said that the request body should send back two parameters: replyToken and messages (please see the screenshot) offical reply_message SDK document link

the SDK document of reply message function screenshot

It said put the array of message object into message parameter. And the array of message object is look like: the SDK document of message object example link

the SDK document of message object screenshot

Another way I found that someone using PHP to implement by using this function.

PHP implement method example

But I still can't find the solution how to send multi messages in the reply_message function by using Python..

I tried to code in Python is:

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

The error message is:

TypeError: reply_message() missing 1 required positional argument: 'messages'

error message log

I tried another way to put parameters, but still can't work

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

the error message is:

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

How can this be done in Python?

1 Answers

Finally, I found the solution.

Here is the example:

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