-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrichmessage_bot.py
More file actions
141 lines (129 loc) · 3.89 KB
/
richmessage_bot.py
File metadata and controls
141 lines (129 loc) · 3.89 KB
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
# -*- coding: utf-8 -*-
import time
import os
import random
from rocketchat_py_sdk.driver import Driver
bot_username = os.getenv('BOT_USERNAME', 'bot_rasa')
bot_password = os.getenv('BOT_PASSWORD', 'bot_rasa')
rocket_url = os.getenv('ROCKET_URL', 'localhost:3000')
attachmentDict = {
"text button with url": [{
"title": "text button with url",
"actions": [
{
"type": "button",
"text": "Book flights",
"url": "http://www.kayak.com",
"is_webview": False
}
]
}],
"text button with msg in chat window":[{
"title": "text button with msg in chat window",
"actions": [
{
"type": "button",
"text": "Say hello in chat window?",
"msg": "hello in chat window",
"msg_in_chat_window": True
}
]
}],
"image button with url":[{
"title": "image button with url",
"actions": [
{
"type": "button",
"url": "http://www.kayak.com",
"image_url": "http://www.emoji.co.uk/files/phantom-open-emojis/travel-places-phantom/12698-airplane.png",
"is_webview": False
}
]
}],
"image button with msg in chat window":[{
"title": "image button with msg in chat window",
"actions": [
{
"type": "button",
"image_url": "http://www.emoji.co.uk/files/phantom-open-emojis/travel-places-phantom/12698-airplane.png",
"msg": "I clicked the airplane",
"msg_in_chat_window": True
}
]
}],
"multiple text buttons":[{
"title": "multiple text buttons with url",
"actions": [
{
"type": "button",
"text": "Book flights",
"url": "http://www.kayak.com",
"is_webview": False
},
{
"type": "button",
"text": "Cancel travel request",
"url": "https://requests.example.com/cancel/r123456",
"is_webview": False
}
]
}],
"horizontal text buttons":[{
"title": "horizontal text buttons with url",
"button_alignment": "horizontal",
"actions": [
{
"type": "button",
"text": "Book flights",
"url": "http://www.kayak.com",
"is_webview": False
},
{
"type": "button",
"text": "Cancel travel request",
"url": "https://requests.example.com/cancel/r123456",
"is_webview": False
}
]
}],
"attachment with buttons":[{
"title": "Lauri M(title field)",
"title_link": "https://www.basketball-reference.com/players/m/markkla01.html",
"text": "Should have been rookie of the year (text field)",
"description": "What a great player! (description field)",
"image_url": "http://www.trbimg.com/img-5b04c449/turbine/ct-spt-bulls-lauri-markkanen-all-rookie-team-20180522",
"actions": [
{
"type": "button",
"text": "Book flights",
"url": "https://www.kayak.com",
"is_webview": False
},
{
"type": "button",
"text": "Cancel travel request",
"url": "https://www.kayak.com",
"is_webview": False
}
]
}]
}
replyDict = {
"hello in chat window": "received your ‘hello in chat window’",
"I clicked the airplane": "received your response about clicking the airplane"
}
def process_message(bot, message):
text = message['msg']
if(text in attachmentDict):
bot.send_attachment(message['rid'], attachmentDict[text])
elif(text in replyDict):
bot.send_message(message['rid'], replyDict[text])
def start(bot):
bot.connect()
bot.login(user=bot_username, password=bot_password)
bot.subscribe_to_messages()
bot.add_prefix_handler('', process_message)
while True:
time.sleep(3600)
if __name__ == '__main__':
start(Driver(url=rocket_url, ssl=False, debug=True))