學習Line Bot心得
Message types
其他資訊來源
Code
## Text 文字
line_bot_api.reply_message(event.reply_token,
TextSendMessage(text=event.message.text))
## Sticker 貼圖
line_bot_api.reply_message(event.reply_token,
StickerSendMessage(package_id=1, sticker_id=2))
## Image 圖片
line_bot_api.reply_message(event.reply_token,
ImageSendMessage(original_content_url='圖片網址', preview_image_url='圖片網址'))
## Video
line_bot_api.reply_message(event.reply_token,
VideoSendMessage(original_content_url='影片網址', preview_image_url='預覽的圖片網址'))
## Audio
line_bot_api.reply_message(event.reply_token,
AudioSendMessage(original_content_url='音訊網址', duration=100000))
## Location
line_bot_api.reply_message(event.reply_token,
LocationSendMessage(title='my location', address='Tainan', latitude=22.994821, longitude=120.196452))
## Imagemap
imagemap_message = ImagemapSendMessage(
base_url=''
alt_text='this is an imagemap',
base_size=BaseSize(height=520, width=520),
actions=[
URIImagemapAction(
link_uri='',
area=ImagemapArea(
x=174, y=65, width=707, height=416
)
),
MessageImagemapAction(
text='hello',
area=ImagemapArea(
x=520, y=0, width=520, height=520
)
)
]
)
line_bot_api.reply_message(event.reply_token, imagemap_message)
## Template
### Buttons
buttons_template = TemplateSendMessage(
alt_text='Buttons Template',
template=ButtonsTemplate(
title='這是ButtonsTemplate',
text='ButtonsTemplate可以傳送text,uri',
thumbnail_image_url='顯示在開頭的大圖片網址',
actions=[
MessageTemplateAction(
label='ButtonsTemplate',
text='ButtonsTemplate'
),
URITemplateAction(
label='VIDEO1',
uri='影片網址'
),
PostbackTemplateAction(
label='postback',
text='postback text',
data='postback1'
)
]
)
)
line_bot_api.reply_message(event.reply_token, buttons_template)
### Confirm
Confirm_template = TemplateSendMessage(
alt_text='目錄 template',
template=ConfirmTemplate(
title='這是ConfirmTemplate',
text='這就是ConfirmTemplate,用於兩種按鈕選擇',
actions=[
PostbackTemplateAction(
label='Y',
text='Y',
data='action=buy&itemid=1'
),
MessageTemplateAction(
label='N',
text='N'
)
]
)
)
line_bot_api.reply_message(event.reply_token,Confirm_template)
### Carousel
Carousel_template = TemplateSendMessage(
alt_text='Carousel template',
template=CarouselTemplate(
columns=[
CarouselColumn(
thumbnail_image_url='顯示在開頭的大圖片網址',
title='this is menu1',
text='description1',
actions=[
PostbackTemplateAction(
label='postback1',
text='postback text1',
data='action=buy&itemid=1'
),
MessageTemplateAction(
label='message1',
text='message text1'
),
URITemplateAction(
label='uri1',
uri='http://example.com/1'
)
]
),
CarouselColumn(
thumbnail_image_url='顯示在開頭的大圖片網址',
title='this is menu2',
text='description2',
actions=[
PostbackTemplateAction(
label='postback2',
text='postback text2',
data='action=buy&itemid=2'
),
MessageTemplateAction(
label='message2',
text='message text2'
),
URITemplateAction(
label='連結2',
uri='http://example.com/2'
)
]
)
]
)
)
line_bot_api.reply_message(event.reply_token,Carousel_template)
### Image carousel
Image_Carousel = TemplateSendMessage(
alt_text='目錄 template',
template=ImageCarouselTemplate(
columns=[
ImageCarouselColumn(
image_url='圖片網址',
action=PostbackTemplateAction(
label='postback1',
text='postback text1',
data='action=buy&itemid=1'
)
),
ImageCarouselColumn(
image_url='圖片網址',
action=PostbackTemplateAction(
label='postback2',
text='postback text2',
data='action=buy&itemid=2'
)
)
]
)
)
line_bot_api.reply_message(event.reply_token,Image_Carousel)