Skip to content
This repository was archived by the owner on Jun 19, 2019. It is now read-only.

Commit 05bd15f

Browse files
committed
added topic suggestion option and notification
1 parent 66cf6b1 commit 05bd15f

File tree

3 files changed

+86
-31
lines changed

3 files changed

+86
-31
lines changed

src/app.py

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
from utils.log_manager import setup_logging
55
from decouple import config
66
import traceback
7+
from pprint import pprint
8+
79

810
from src.help_menu import HELP_MENU_RESPONSES
9-
from src.messages import HELP_MENU, MESSAGE, needs_greet_button, greeted_response_attachments
11+
from src.messages import HELP_MENU, MESSAGE, needs_greet_button, greeted_response_attachments, SUGGESTION_MODAL
1012

1113
logger = logging.getLogger(__name__)
1214
new_event_logger = logging.getLogger(f'{__name__}.new_member')
@@ -19,9 +21,10 @@
1921
# COMMUNITY_CHANNEL = config('PERSONAL_PRIVATE_CHANNEL')
2022

2123
TOKEN = config('OPCODE_APP_TOKEN')
22-
COMMUNITY_CHANNEL = config('OPCODE_REWRITE_CHANNEL')
23-
PROJECTS_CHANNEL = config('OPCODE_OC_PROJECTS_CHANNEL')
24+
# COMMUNITY_CHANNEL = config('OPCODE_REWRITE_CHANNEL')
25+
# PROJECTS_CHANNEL = config('OPCODE_OC_PROJECTS_CHANNEL')
2426
# COMMUNITY_CHANNEL = config('OPCODE_COMMUNITY_ID')
27+
COMMUNITY_CHANNEL = config('OPCODE_BOT_TESTING_CHANNEL')
2528

2629
PROXY = PROXY if PROXY else None
2730
slack_client = SlackClient(TOKEN, proxies=PROXY)
@@ -39,9 +42,9 @@ def event_handler(event_dict: dict) -> None:
3942
:param event_dict:
4043
"""
4144
# all_event_logger.info(event_dict)
42-
if event_dict['type'] == 'team_join':
43-
new_event_logger.info('New member event recieved')
44-
new_member(event_dict)
45+
# if event_dict['type'] == 'team_join':
46+
# new_event_logger.info('New member event recieved')
47+
# new_member(event_dict)
4548

4649
""" Trigger for testing team_join event """
4750
if event_dict['type'] == 'message' and 'user' in event_dict.keys() and event_dict['text'] == 'testgreet':
@@ -55,12 +58,21 @@ def help_menu_interaction(data: dict) -> None:
5558
displayed message
5659
:param data:
5760
"""
58-
params = {'text': ' \n\n\n' + HELP_MENU_RESPONSES[data['actions'][0]['value']],
59-
'channel': data['channel']['id'],
60-
'ts': data['message_ts'],
61-
'as_user': True
62-
}
63-
slack_client.api_call('chat.update', **params)
61+
62+
response = data['actions'][0]['value']
63+
64+
if response == 'suggestion':
65+
trigger_id = data['trigger_id']
66+
res = slack_client.api_call('dialog.open', trigger_id=trigger_id, dialog=SUGGESTION_MODAL)
67+
pprint(res)
68+
69+
else:
70+
params = {'text': ' \n\n\n' + HELP_MENU_RESPONSES[data['actions'][0]['value']],
71+
'channel': data['channel']['id'],
72+
'ts': data['message_ts'],
73+
'as_user': True
74+
}
75+
slack_client.api_call('chat.update', **params)
6476

6577

6678
def greeted_interaction(data: dict) -> dict:
@@ -91,6 +103,13 @@ def greeted_interaction(data: dict) -> dict:
91103
res = slack_client.api_call("chat.update", **params)
92104

93105

106+
def suggestion_submission(data):
107+
suggestion = data['submission']['suggestion']
108+
user_id = data['user']['id']
109+
message = f"<@{user_id}> just submitted a suggestion for a help topic:\n{suggestion}"
110+
res = slack_client.api_call('chat.postMessage', channel=COMMUNITY_CHANNEL, text=message)
111+
112+
94113
def new_member(event_dict: dict) -> None:
95114
new_event_logger.info('Recieved json event: {}'.format(event_dict))
96115

@@ -102,27 +121,27 @@ def new_member(event_dict: dict) -> None:
102121
custom_message = MESSAGE.format(real_name=real_name)
103122

104123
new_event_logger.info('Built message: {}'.format(custom_message))
105-
response = slack_client.api_call('chat.postMessage',
106-
channel=user_id,
107-
# channel=COMMUNITY_CHANNEL, # testing option
108-
# as_user=True, # Currently not working. DM comes from my account
109-
text=custom_message)
124+
# response = slack_client.api_call('chat.postMessage',
125+
# # channel=user_id,
126+
# channel=COMMUNITY_CHANNEL, # testing option
127+
# # as_user=True, # Currently not working. DM comes from my account
128+
# text=custom_message)
110129

111130
r2 = slack_client.api_call('chat.postMessage',
112-
channel=user_id,
113-
# channel=COMMUNITY_CHANNEL, # testing option
131+
# channel=user_id,
132+
channel=COMMUNITY_CHANNEL, # testing option
114133
# as_user=True,
115134
**HELP_MENU)
116135

117136
# Notify #community
118137
text = f":tada: <@{user_id}> has joined the Slack team :tada:"
119138
slack_client.api_call('chat.postMessage', channel=COMMUNITY_CHANNEL,
120139
text=text, attachments=needs_greet_button())
121-
122-
if response['ok']:
123-
new_event_logger.info('New Member Slack response: Response 1: {} \nResponse2: {}'.format(response, r2))
124-
else:
125-
new_event_logger.error('FAILED -- Message to new member returned error: {}'.format(response))
140+
#
141+
# if response['ok']:
142+
# new_event_logger.info('New Member Slack response: Response 1: {} \nResponse2: {}'.format(response, r2))
143+
# else:
144+
# new_event_logger.error('FAILED -- Message to new member returned error: {}'.format(response))
126145

127146

128147
def parse_slack_output(slack_rtm_output: list) -> None:
@@ -157,10 +176,10 @@ def join_channels():
157176
"""
158177
response = slack_client.api_call('channels.join', name='general')
159178
print(response)
179+
# set the defalt to a 1 second delay
160180

161181

162-
# set the defalt to a 1 second delay
163-
def run_bot(delay: int=1) -> None:
182+
def run_bot(delay: int = 1) -> None:
164183
"""
165184
Runs the bot using the Slack Real Time Messaging API.
166185
**Doesn't provide events or interactive functionality
@@ -183,4 +202,4 @@ def run_bot(delay: int=1) -> None:
183202

184203

185204
if __name__ == '__main__':
186-
run_bot()
205+
run_bot()

src/flask_endpoint.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from pprint import pprint
2+
13
from flask import Flask, request, make_response
24
from decouple import config
35
import json
@@ -8,8 +10,6 @@
810
app = Flask(__name__)
911

1012
VERIFICATION_TOKEN = config('OPCODE_VERIFICATION_TOKEN')
11-
12-
1313
# VERIFICATION_TOKEN = config('APP_VERIFICATION_TOKEN')
1414

1515

@@ -25,11 +25,15 @@ def interaction():
2525
print("Bad request")
2626
return make_response("", 403)
2727
callback = data['callback_id']
28+
pprint(data['user'])
2829

2930
if callback == 'greeting_buttons':
3031
bot.help_menu_interaction(data)
3132
elif callback == 'greeted':
3233
bot.greeted_interaction(data)
34+
elif callback == 'suggestion_modal':
35+
pprint(data)
36+
bot.suggestion_submission(data)
3337
return make_response('', 200)
3438

3539

src/messages.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
"You can download it <https://slack.com/downloads|here.>\n\n"
99
"Want to make your first change to a program right now? "
1010
"All active Operation Code Projects are located on our source control repository. "
11-
"Our projects can be viewed on <https://github.com/OperationCode/START_HERE|Github.>")
11+
"Our projects can be viewed on <https://github.com/OperationCode/START_HERE|Github.>\n\n"
12+
"Click any of the buttons below to receive more information on the topic.\n\n"
13+
"If you'd like to see something that isn't here let us know!")
1214

1315
HELP_MENU = {
14-
"text": "Click any of the buttons below to receive more information on the topic.",
16+
"text": "",
1517
"attachments": [
1618
{
1719
"text": "",
@@ -53,11 +55,41 @@
5355
"type": "button",
5456
"value": "ruby_help",
5557
},
58+
59+
]
60+
},
61+
{
62+
"text": "",
63+
"fallback": "",
64+
"color": "#3AA3E3",
65+
"callback_id": "greeting_buttons",
66+
"attachment_type": "default",
67+
"actions": [
68+
{
69+
"name": "suggestion",
70+
"text": "Are we missing something? Click!",
71+
"type": "button",
72+
"value": "suggestion",
73+
},
5674
]
5775
}
5876
]
5977
}
6078

79+
SUGGESTION_MODAL = {
80+
"callback_id": "suggestion_modal",
81+
"title": "Help topic suggestion",
82+
"submit_label": "Suggestion",
83+
"elements": [
84+
{
85+
"type": "text",
86+
"label": "Suggestion",
87+
"name": "suggestion",
88+
"placeholder": "Underwater Basket Weaving"
89+
},
90+
]
91+
}
92+
6193

6294
def greeted_response_attachments(clicker: str) -> list:
6395
return [

0 commit comments

Comments
 (0)