Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

respond-to-feedback email feature #688

Merged
merged 1 commit into from
Jun 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions server/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ GITHUB_SHA=DEVELOPMENT
SLACK_WEBHOOK_URL=
SLACK_ERROR_CODES=[400, 500]

# Sendgrid
SENDGRID_API_KEY=

######################### DOCKER-COMPOSE SETTINGS ########################

COMPOSE_PROJECT_NAME=311_data
Expand Down
10 changes: 6 additions & 4 deletions server/api/src/control/route_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
comparison as comp_svc,
github as github_svc,
map as map_svc,
status as status_svc)
status as status_svc,
email as email_svc)


async def index(request):
Expand Down Expand Up @@ -92,7 +93,8 @@ async def feedback(request):
'title': to.req.STR,
'body': to.req.STR})

issue_id = await github_svc.create_issue(args['title'], args['body'])
response = await github_svc.add_issue_to_project(issue_id)
id, number = await github_svc.create_issue(args['title'], args['body'])
await github_svc.add_issue_to_project(id)
await email_svc.respond_to_feedback(args['body'], number)

return json(response)
return json({'success': True})
37 changes: 37 additions & 0 deletions server/api/src/services/email.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail
from settings import Sendgrid


API_KEY = Sendgrid.API_KEY
FROM_ADDRESS = '[email protected]'


def response(first_name, issue_number, feedback):
return f'''\
{first_name},

Thank you for contacting 311-data.org. A ticket has been created (#{issue_number}) and an email has been sent to our support team. Please be patient with our response time since we are all volunteers.

Below is the information that we received from you:
{feedback}

Thanks again for your interest and we look forward to working with you.

If you have any questions, feel free to contact us at [email protected]

'''.replace('\n', '<br/>') # noqa: E501


async def respond_to_feedback(feedback, issue_number):
first_name, _, email, *__ = feedback.split('\n')
first_name = first_name.replace('First name: ', '')
email = email.replace('Email: ', '')

message = Mail(
from_email=FROM_ADDRESS,
to_emails=[email, FROM_ADDRESS],
subject='Thanks for your feedback',
html_content=response(first_name, issue_number, feedback))

return SendGridAPIClient(API_KEY).send(message)
3 changes: 2 additions & 1 deletion server/api/src/services/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ async def create_issue(title,
response.raise_for_status()
response_content = loads(response.content)
issue_id = response_content['id']
return issue_id
issue_number = response_content['number']
return issue_id, issue_number
except requests.exceptions.HTTPError as errh:
return errh
except requests.exceptions.ConnectionError as errc:
Expand Down
4 changes: 4 additions & 0 deletions server/api/src/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,7 @@ class Socrata:
class Slack:
WEBHOOK_URL = env('SLACK_WEBHOOK_URL')
ERROR_CODES = env('SLACK_ERROR_CODES', to.LIST_OF_INTS)


class Sendgrid:
API_KEY = env('SENDGRID_API_KEY')