-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot-logic.py
81 lines (67 loc) · 1.91 KB
/
bot-logic.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
"""
sample config module
run "cp config.sample.py config.py" to create local config
edit config.py functions to override default bot behavior
"""
__name__ = 'localConfig'
__package__ = 'ringcentral_bot_framework'
import pydash as _
import json
def helpMsg(botId, groupId, user, authed = False):
authUrl = user.getAuthUri(groupId, botId)
loginStr = ''
if authed == False:
loginStr = f' I **needs your authorization** before I can process your cmd. [Click here]({authUrl}) to authorize the bot.'
return f'''Hello, I am the assistant bot. Please reply "@ **cmd**" if you want me to show your user/company infomation.{loginStr}
**cmd** list
**user info** -- show your user info
**company info** -- show your company info
'''
def botJoinPrivateChatAction(bot, groupId, user, dbAction):
"""
bot join private chat event handler
bot could send some welcome message or help, or something else
"""
bot.sendMessage(
groupId,
{
'text': helpMsg(bot.id, groupId, user)
}
)
def botGotPostAddAction(
bot,
groupId,
creatorId,
user,
text,
dbAction,
handledByExtension,
event
):
"""
bot got group chat message: text
bot could send some response
"""
if not f'' in text:
return
msg = ''
if user.id == '':
msg = helpMsg(bot.id, groupId, user)
elif 'user info' in text:
userInfo = user.platform.get('/restapi/v1.0/account/~/extension/~')
txt = json.loads(userInfo.text())
txt = json.dumps(txt, indent=2)
msg = f' your user info json is:\n' + txt
elif 'company info' in text:
compInfo = user.platform.get('/restapi/v1.0/account/~')
txt = json.loads(compInfo.text())
txt = json.dumps(txt, indent=2)
msg = f' your company info json is:\n' + txt
else:
msg = helpMsg(bot.id, groupId, user, True)
bot.sendMessage(
groupId,
{
'text': msg
}
)