Closed thirza258 closed 2 weeks ago
Thank you for using line-bot-sdk-python, @thirza258 !
Is the import section of the sample you provided correct? PushMessageRequest
exists only in linebot.v3.messaging
.
from linebot.v3.messaging import (
Configuration,
ApiClient,
MessagingApi,
PushMessageRequest,
TextMessage
...
)
It probably needs to be imported like this. Also, I think you need to define the client as shown in the README sample. https://github.com/line/line-bot-sdk-python?tab=readme-ov-file#synopsis
and ...
The sample in README:
ReplyMessageRequest(
reply_token=event.reply_token,
messages=[TextMessage(text=event.message.text)]
)
should work if rewritten like this, if you want to use push:
I'm sorry that's true (looks like i'm making mistake on making the question) I'm using the following import statement in my implementation:
from linebot.v3.messaging import (
Configuration,
ApiClient,
MessagingApi,
PushMessageRequest,
TextMessage
...
)
My implementation is primarily derived from the examples/flask-kitchensink/app.py example.
Based on the examples, I need to first send a "push" message to the Line bot by chatting "push" to it:
@handler.add(MessageEvent, message=TextMessageContent)
def handle_text_message(event):
text = event.message.text
with ApiClient(configuration) as api_client:
line_bot_api = MessagingApi(api_client)
{other code}
elif text == 'push':
line_bot_api.push_message(
PushMessageRequest(
to=event.source.user_id,
messages=[TextMessage(text='PUSH!')]
)
)
This will push the messages. What I expect is that when a user sends a POST request (example: making a comment) to my website that is the webhook website too, the push message gets called and sends the response from the Line bot to me as a chat. It functions like notifications but in the form of a chat from the Line bot. Is there any way to do that?
We do not accept questions about general web application development. Sorry. You can save the userId in your application or database, and when your web app receives a request(like making a comment), your application can send a push request to the LINE Messaging API.
If the issue has been resolved, please close the issue.
Thank you so much for your assistance and taking the time to answer this question. I just figured it out. It turned out i'm using TextMessage instead of TextSendMessage. :)
Question : Is there any way to Call Push Messages from Website POST Request
Description
I am trying to call the
push_message
function in my Django project when a POST request is made to my website. Thepush_message
function should send a push message using the LINE Bot API. However, I am encountering issues with validation errors. Below is my current implementation.Current Implementation example
Views
by the way, the code above not the real implementation but the example for real implementation
Problem I am encountering the following error when trying to call the push_message function:
Any assistance or guidance on resolving this issue would be greatly appreciated. Thank you!