-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #144 from curranjm/add_user_feedback_intent_104
Add user feedback intent 104
- Loading branch information
Showing
3 changed files
with
224 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
""" | ||
The feedback intent allows the user to provide feedback about the skill, | ||
including bug reports and suggestions for new intents. | ||
""" | ||
|
||
from mycity.mycity_response_data_model import MyCityResponseDataModel | ||
import requests | ||
import json | ||
import os | ||
|
||
SLACK_WEBHOOKS_URL = os.environ['SLACK_WEBHOOKS_URL'] | ||
|
||
|
||
def submit_feedback(mycity_request): | ||
""" | ||
Logs user feedback to the mycity-feedback slack channel. | ||
:param mycity_request: MyCityRequestDataModel object | ||
:return: MyCityResponseDataModel object | ||
""" | ||
print( | ||
'[module: feedback_intent]', | ||
'[method: submit_feedback]', | ||
'MyCityRequestDataModel received:', | ||
str(mycity_request) | ||
) | ||
# get the intent_variables object from the request | ||
intent_variables = mycity_request.intent_variables | ||
|
||
# Build the response. | ||
# - if we are missing the feedback type or feedback text, we'll delegate | ||
# to the dialog model to request the missing information | ||
# - if we have everything we need, we'll pose the message to slack and | ||
# confirm to the user | ||
mycity_response = MyCityResponseDataModel() | ||
mycity_response.session_attributes = mycity_request.session_attributes | ||
mycity_response.should_end_session = False | ||
if ( | ||
'value' not in intent_variables['FeedbackType'] or | ||
'value' not in intent_variables['Feedback'] | ||
): | ||
mycity_response.intent_variables = intent_variables | ||
mycity_response.dialog_directive = "Delegate" | ||
return mycity_response | ||
else: | ||
feedback_type = intent_variables['FeedbackType']['value'] | ||
feedback_text = intent_variables['Feedback']['value'] | ||
status = send_to_slack( | ||
build_slack_message(feedback_type, feedback_text) | ||
) | ||
if status == 200: | ||
mycity_response.output_speech = 'Thanks for your feedback.' | ||
else: | ||
mycity_response.output_speech = \ | ||
'There was a problem with your feedback. Please try again.' | ||
mycity_response.reprompt_text = None | ||
mycity_response.session_attributes = mycity_request.session_attributes | ||
mycity_response.card_title = "Feedback" | ||
return mycity_response | ||
|
||
|
||
def send_to_slack(message): | ||
""" | ||
Posts feedback in the mycity-feedback Slack channel via HTTP request. | ||
:param message: | ||
:return: | ||
""" | ||
print( | ||
'[module: feedback_intent]', | ||
'[method: send_to_slack]', | ||
'message received:', | ||
message | ||
) | ||
data = json.dumps({'text': message}) | ||
headers = {'Content-Type': 'application/json'} | ||
request = requests.post(SLACK_WEBHOOKS_URL, data, headers) | ||
return request.status_code | ||
|
||
|
||
def build_slack_message(feedback_type, feedback_text): | ||
""" | ||
Configures the message we will post to slack. | ||
:param feedback_type: | ||
:param feedback_text: | ||
:return: | ||
""" | ||
print( | ||
'[module: feedback_intent]', | ||
'[method: build_slack_message]', | ||
'feedback type and text received:', | ||
feedback_type + ', ' + feedback_text | ||
) | ||
emoji = ':bug:' if feedback_type == 'bug' else ':bulb:' | ||
return emoji + '\n>' + feedback_text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters