forked from maso0310/linebot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessage.py
212 lines (204 loc) · 8.53 KB
/
message.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#這些是LINE官方開放的套件組合透過import來套用這個檔案上
from linebot import (LineBotApi, WebhookHandler)
from linebot.exceptions import (InvalidSignatureError)
from linebot.models import *
#ImagemapSendMessage(組圖訊息)
def imagemap_message():
message = ImagemapSendMessage(
base_url="https://i.imgur.com/BfTFVDN.jpg",
alt_text='最新的合作廠商有誰呢?',
base_size=BaseSize(height=2000, width=2000),
actions=[
URIImagemapAction(
#家樂福
link_uri="https://tw.shop.com/search/%E5%AE%B6%E6%A8%82%E7%A6%8F",
area=ImagemapArea(
x=0, y=0, width=1000, height=1000
)
),
URIImagemapAction(
#生活市集
link_uri="https://tw.shop.com/search/%E7%94%9F%E6%B4%BB%E5%B8%82%E9%9B%86",
area=ImagemapArea(
x=1000, y=0, width=1000, height=1000
)
),
URIImagemapAction(
#阿瘦皮鞋
link_uri="https://tw.shop.com/search/%E9%98%BF%E7%98%A6%E7%9A%AE%E9%9E%8B",
area=ImagemapArea(
x=0, y=1000, width=1000, height=1000
)
),
URIImagemapAction(
#塔吉特千層蛋糕
link_uri="https://tw.shop.com/search/%E5%A1%94%E5%90%89%E7%89%B9",
area=ImagemapArea(
x=1000, y=1000, width=1000, height=500
)
),
URIImagemapAction(
#亞尼克生乳捲
link_uri="https://tw.shop.com/search/%E4%BA%9E%E5%B0%BC%E5%85%8B",
area=ImagemapArea(
x=1000, y=1500, width=1000, height=500
)
)
]
)
return message
#TemplateSendMessage - ButtonsTemplate (按鈕介面訊息)
def buttons_message():
message = TemplateSendMessage(
alt_text='好消息來囉~',
template=ButtonsTemplate(
thumbnail_image_url="https://pic2.zhimg.com/v2-de4b8114e8408d5265503c8b41f59f85_b.jpg",
title="是否要進行抽獎活動?",
text="輸入生日後即獲得抽獎機會",
actions=[
DatetimePickerTemplateAction(
label="請選擇生日",
data="input_birthday",
mode='date',
initial='1990-01-01',
max='2019-03-10',
min='1930-01-01'
),
MessageTemplateAction(
label="看抽獎品項",
text="有哪些抽獎品項呢?"
),
URITemplateAction(
label="免費註冊享回饋",
uri="https://tw.shop.com/nbts/create-myaccount.xhtml?returnurl=https%3A%2F%2Ftw.shop.com%2F"
)
]
)
)
return message
#TemplateSendMessage - ConfirmTemplate(確認介面訊息)
def Confirm_Template():
message = TemplateSendMessage(
alt_text='是否註冊成為會員?',
template=ConfirmTemplate(
text="是否註冊成為會員?",
actions=[
PostbackTemplateAction(
label="馬上註冊",
text="現在、立刻、馬上",
data="會員註冊"
),
MessageTemplateAction(
label="查詢其他功能",
text="查詢其他功能"
)
]
)
)
return message
#旋轉木馬按鈕訊息介面
def Carousel_Template():
message = TemplateSendMessage(
alt_text='一則旋轉木馬按鈕訊息',
template=CarouselTemplate(
columns=[
CarouselColumn(
thumbnail_image_url='https://upload.wikimedia.org/wikipedia/commons/thumb/8/88/Number_1_in_green_rounded_square.svg/200px-Number_1_in_green_rounded_square.svg.png',
title='這是第一塊模板',
text='一個模板可以有三個按鈕',
actions=[
PostbackTemplateAction(
label='回傳一個訊息',
data='將這個訊息偷偷回傳給機器人'
),
MessageTemplateAction(
label='用戶發送訊息',
text='我知道這是1'
),
URITemplateAction(
label='進入1的網頁',
uri='https://upload.wikimedia.org/wikipedia/commons/thumb/8/88/Number_1_in_green_rounded_square.svg/200px-Number_1_in_green_rounded_square.svg.png'
)
]
),
CarouselColumn(
thumbnail_image_url='https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRuo7n2_HNSFuT3T7Z9PUZmn1SDM6G6-iXfRC3FxdGTj7X1Wr0RzA',
title='這是第二塊模板',
text='副標題可以自己改',
actions=[
PostbackTemplateAction(
label='回傳一個訊息',
data='這是ID=2'
),
MessageTemplateAction(
label='用戶發送訊息',
text='我知道這是2'
),
URITemplateAction(
label='進入2的網頁',
uri='https://upload.wikimedia.org/wikipedia/commons/thumb/c/cd/Number_2_in_light_blue_rounded_square.svg/200px-Number_2_in_light_blue_rounded_square.svg.png'
)
]
),
CarouselColumn(
thumbnail_image_url='https://upload.wikimedia.org/wikipedia/commons/thumb/e/e4/Number_3_in_yellow_rounded_square.svg/200px-Number_3_in_yellow_rounded_square.svg.png',
title='這是第三個模塊',
text='最多可以放十個',
actions=[
PostbackTemplateAction(
label='回傳一個訊息',
data='這是ID=3'
),
MessageTemplateAction(
label='用戶發送訊息',
text='我知道這是3'
),
URITemplateAction(
label='uri2',
uri='https://upload.wikimedia.org/wikipedia/commons/thumb/e/e4/Number_3_in_yellow_rounded_square.svg/200px-Number_3_in_yellow_rounded_square.svg.png'
)
]
)
]
)
)
return message
#TemplateSendMessage - ImageCarouselTemplate(圖片旋轉木馬)
def image_carousel_message1():
message = TemplateSendMessage(
alt_text='圖片旋轉木馬',
template=ImageCarouselTemplate(
columns=[
ImageCarouselColumn(
image_url="https://i.imgur.com/uKYgfVs.jpg",
action=URITemplateAction(
label="新鮮水果",
uri="http://img.juimg.com/tuku/yulantu/110709/222-110F91G31375.jpg"
)
),
ImageCarouselColumn(
image_url="https://i.imgur.com/QOcAvjt.jpg",
action=URITemplateAction(
label="新鮮蔬菜",
uri="https://cdn.101mediaimage.com/img/file/1410464751urhp5.jpg"
)
),
ImageCarouselColumn(
image_url="https://i.imgur.com/Np7eFyj.jpg",
action=URITemplateAction(
label="可愛狗狗",
uri="http://imgm.cnmo-img.com.cn/appimg/screenpic/big/674/673928.JPG"
)
),
ImageCarouselColumn(
image_url="https://i.imgur.com/QRIa5Dz.jpg",
action=URITemplateAction(
label="可愛貓咪",
uri="https://m-miya.net/wp-content/uploads/2014/07/0-065-1.min_.jpg"
)
)
]
)
)
return message
#關於LINEBOT聊天內容範例