今天我們要完成的是機房服務列表,
一個機房可能有其他相關的服務,
我們要做一個簡單就能串連到他們的功能,
首先在message.py新增上,
class roomlable():
def returna(self):
urldata = []
namedata = []
accpasdata= []
statusdata = []
serviceList = ""
for serviceList in serviceListdata.find():
name = serviceList["name"]
url = serviceList["url"]
accpas = serviceList["notice"]
status = serviceList["enabled"]
namedata.append(name)
urldata.append(url)
accpasdata.append(accpas)
statusdata.append(status)
flex_message = FlexSendMessage(
alt_text='hello',
contents={
"type": "bubble",
"size": "mega",
"header": {
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "text",
"text": "機房服務列表",
"color": "#ffffff",
"size": "xl",
"flex": 4,
"weight": "regular",
"margin": "xs"
}
]
}
],
"paddingAll": "20px",
"backgroundColor": "#0367D3",
"spacing": "md",
"height": "80px",
"paddingTop": "22px"
},
"body": {
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "text",
"text": "服務名稱:"+ str(namedata[0]),
"size": "lg",
"color": "#0367D3"
},
{
"type": "text",
"text": "服務網址:"+ str(urldata[0])
},
{
"type": "text",
"text": "服務啟用狀態:"+ str(statusdata[0])
},
{
"type": "text",
"text": "備註:"+ str(accpasdata[0])
},
{
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "button",
"action": {
"type": "uri",
"label": "ccc",
"uri": "cccc"
},
"color": "#FFFFFF"
}
],
"backgroundColor": "#FFA500"
}
]
}
]
},
{
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "text",
"text": "服務名稱:"+ str(namedata[1]),
"size": "lg",
"color": "#0367D3"
},
{
"type": "text",
"text": "服務網址:"+ str(urldata[1])
},
{
"type": "text",
"text": "服務啟用狀態:" + str(statusdata[1])
},
{
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "button",
"action": {
"type": "uri",
"label": "cccc",
"uri": "cccc"
},
"color": "#FFFFFF"
}
],
"backgroundColor": "#FFA500"
}
]
}
]
},
{
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "text",
"text": "服務名稱:"+ str(namedata[2]),
"size": "lg",
"color": "#0367D3"
},
{
"type": "text",
"text": "服務網址:"+ str(urldata[2])
},
{
"type": "text",
"text": "服務啟用狀態:"+str(statusdata[2])
},
{
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "button",
"action": {
"type": "uri",
"label": "cccc",
"uri": "cccc"
},
"color": "#FFFFFF"
}
],
"backgroundColor": "#FFA500"
}
]
}
]
},
{
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "text",
"text": "服務名稱:"+ str(namedata[3]),
"size": "lg",
"color": "#0367D3"
},
{
"type": "text",
"text": "服務網址:"+ str(urldata[3])
},
{
"type": "text",
"text": "服務啟用狀態:"+str(statusdata[3])
},
{
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "button",
"action": {
"type": "uri",
"label": "cccc",
"uri": "cccc"
},
"color": "#FFFFFF"
}
],
"backgroundColor": "#FFA500"
}
]
}
]
},
{
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "text",
"text": "服務名稱:"+ str(namedata[4]),
"size": "lg",
"color": "#0367D3"
},
{
"type": "text",
"text": "服務網址:"+ str(urldata[4])
},
{
"type": "text",
"text": "服務啟用狀態:"+str(statusdata[4])
},
{
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "button",
"action": {
"type": "uri",
"label": "cccc",
"uri": "ccccc"
},
"color": "#FFFFFF"
}
],
"backgroundColor": "#FFA500"
}
]
}
]
},
{
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "text",
"text": "服務名稱:"+ str(namedata[5]),
"size": "lg",
"color": "#0367D3"
},
{
"type": "text",
"text": "服務網址:"+ str(urldata[5])
},
{
"type": "text",
"text": "服務啟用狀態:"+str(statusdata[5])
},
{
"type": "text",
"text": "備註:"+ str(accpasdata[5])
},
{
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "button",
"action": {
"type": "uri",
"label": "cccc",
"uri": "cccc"
},
"color": "#FFFFFF"
}
],
"backgroundColor": "#FFA500"
}
]
}
]
},
{
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "text",
"text": "服務名稱:"+ str(namedata[6]),
"size": "lg",
"color": "#0367D3"
},
{
"type": "text",
"text": "服務網址:"+ str(urldata[6])
},
{
"type": "text",
"text": "服務啟用狀態:"+str(statusdata[6])
},
{
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "button",
"action": {
"type": "uri",
"label": "cccc",
"uri": "ccccc"
},
"color": "#FFFFFF"
}
],
"backgroundColor": "#FFA500"
}
]
}
]
},
{
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "text",
"text": "服務名稱:"+ str(namedata[7]),
"size": "lg",
"color": "#0367D3"
},
{
"type": "text",
"text": "服務網址:"+ str(urldata[7])
},
{
"type": "text",
"text": "服務啟用狀態:"+str(statusdata[7])
},
{
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "button",
"action": {
"type": "uri",
"label": "ggggg",
"uri": "ggggg"
},
"color": "#FFFFFF"
}
],
"backgroundColor": "#FFA500"
}
]
}
]
},
{
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "text",
"text": "服務名稱:"+ str(namedata[8]),
"size": "lg",
"color": "#0367D3"
},
{
"type": "text",
"text": "服務網址:"+ str(urldata[8])
},
{
"type": "text",
"text": "服務啟用狀態:"+str(statusdata[8])
},
{
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "button",
"action": {
"type": "uri",
"label": "CCC",
"uri": "CCCC"
},
"color": "#FFFFFF"
}
],
"backgroundColor": "#FFA500"
}
]
}
]
},
{
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "text",
"text": "服務名稱:"+ str(namedata[9]),
"size": "lg",
"color": "#0367D3"
},
{
"type": "text",
"text": "服務網址:"+ str(urldata[9])
},
{
"type": "text",
"text": "服務啟用狀態:"+str(statusdata[9])
},
{
"type": "text",
"text": "備註:"+ str(accpasdata[9])
},
{
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "button",
"action": {
"type": "uri",
"label": "CCC",
"uri": "CCCC"
},
"color": "#FFFFFF"
}
],
"backgroundColor": "#FFA500"
}
]
}
]
},
{
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "text",
"text": "服務名稱:"+ str(namedata[10]),
"size": "lg",
"color": "#0367D3"
},
{
"type": "text",
"text": "服務網址:"+ str(urldata[10])
},
{
"type": "text",
"text": "服務啟用狀態:"+str(statusdata[10])
},
{
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "button",
"action": {
"type": "uri",
"label": "CCCC",
"uri": "CCCC"
},
"color": "#FFFFFF"
}
],
"backgroundColor": "#FFA500"
}
]
}
]
}
}
]
}
]
}
]
}
}
)
return flex_message
這邊我有將服務名稱(lable)鏈結網址(uri)改掉,
如果要使用就是在這邊對印對自己想要的即可,
然後在views.py新增上,
if event.message.text == "機房服務列表":
line_bot_api.reply_message( # 回復「機房服務列表」按鈕輪播訊息
event.reply_token,
roomlable().returna()
)
就完成啦!
下一篇將會對於這個小linebot做一個總結。
今天是 陳鈺羲 的 我們不需要我們 網址如下~~~