Q&A

How to reply by using image in Python

I try using this code to reply with an image.

@handler.add(MessageEvent, message=TextMessage)
def handle_message(event):
		msg_from_user = event.message.text
		if msg_from_user == 'image':
        line_bot_api.reply_message(
        event.reply_token,
        image_message = ImageSendMessage(
        original_content_url='image.jpg',
        preview_image_url='image.jpg')
        )

But I got the error:

File "C:\Users\Name\Desktop\pyline\app.py", line 73, in handle_message
    image_message = ImageSendMessage(
NameError: name 'ImageSendMessage' is not defined

Do I have to import some library or I'm using wrong command

My code is running on Python 3.10.0 Os: Win 10 64bit

  • 0
  • 1
  • 262
  • twitter facebook

I think the error never happenes by adding from linebot.models import ImageSendMessage .

  • 0
本当によろしいですか? question.vm