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

Use pinpoint for designated templates #2152

Merged
merged 43 commits into from
May 8, 2024
Merged

Use pinpoint for designated templates #2152

merged 43 commits into from
May 8, 2024

Conversation

sastels
Copy link
Collaborator

@sastels sastels commented Apr 5, 2024

Summary | Résumé

We add two main features here:

  • Use an AWS Pinpoint pool to send messages from specified templates (other templates not affected).
  • add a task to process pinpoint delivery receipts

This code can be merged in and will sit unused unless

  • the required env vars are set
  • an sms is sent using one of the designated templates.

In other cases the normal sns code will be used to send the text.

Related Issues | Cartes liées

Test instructions | Instructions pour tester la modification

  • set your AWS_PINPOINT_SC_POOL_ID env variable to the pool id in staging AWS_PINPOINT_POOL_ID = "pool-b20333ce1e4e49309ba1db3bf94a3f57"
  • set the env var AWS_PINPOINT_SC_TEMPLATE_IDS to a list of your sms template ids. Just one is ok, ie AWS_PINPOINT_SC_TEMPLATE_IDS = 000000-1111-2222-3333-444444444
  • send an sms using a template in the list. You should see a line such as AWS Pinpoint request finished in ... in the celery logs
  • send an sms using a different template. Instead of the Pinpoint line you should see AWS SNS request finished in ...
  • note that both sends could be from the same number.

Release Instructions | Instructions pour le déploiement

None.

Reviewer checklist | Liste de vérification du réviseur

  • This PR does not break existing functionality.
  • This PR does not violate GCNotify's privacy policies.
  • This PR does not raise new security concerns. Refer to our GC Notify Risk Register document on our Google drive.
  • This PR does not significantly alter performance.
  • Additional required documentation resulting of these changes is covered (such as the README, setup instructions, a related ADR or the technical documentation).

⚠ If boxes cannot be checked off before merging the PR, they should be moved to the "Release Instructions" section with appropriate steps required to verify before release. For example, changes to celery code may require tests on staging to verify that performance has not been affected.

app/clients/sms/aws_pinpoint.py Fixed Show fixed Hide fixed
app/clients/sms/aws_pinpoint.py Dismissed Show dismissed Hide dismissed
app/clients/sms/aws_pinpoint.py Fixed Show fixed Hide fixed
@sastels sastels force-pushed the rough-in-pinpoint branch from ba16317 to 0fa34c1 Compare April 9, 2024 20:27
app/clients/sms/aws_pinpoint.py Fixed Show fixed Hide fixed
app/clients/sms/aws_pinpoint.py Fixed Show fixed Hide fixed
@sastels sastels force-pushed the rough-in-pinpoint branch from fc9eeb3 to 3cad558 Compare April 12, 2024 19:14
@sastels sastels force-pushed the rough-in-pinpoint branch from 3cad558 to 6e3d339 Compare April 12, 2024 19:18
# "totalMessageParts": 1,
# "totalMessagePrice": 0.00581,
# "totalCarrierFee": 0.006
# }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice documentation to have in the code!

@sastels sastels force-pushed the rough-in-pinpoint branch from 8f76363 to 6c090ce Compare April 22, 2024 21:12
@sastels sastels changed the title WIP: rough in pinpoint Use pinpoint for designated templates Apr 22, 2024
@sastels sastels marked this pull request as ready for review April 23, 2024 14:05
@sastels sastels force-pushed the rough-in-pinpoint branch from ba2af27 to 40e4c87 Compare May 6, 2024 17:12
@sastels sastels force-pushed the rough-in-pinpoint branch from 177d079 to f09cec5 Compare May 6, 2024 17:24
case "phone is currently unreachable/unavailable":
return NOTIFICATION_PERMANENT_FAILURE

return None
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the cleanest way to use matching, but I think it's even better with if/elifs:

    if "blocked" in response_lower:
        return NOTIFICATION_TECHNICAL_FAILURE
    elif "invalid" in response_lower:
        return NOTIFICATION_TECHNICAL_FAILURE
    elif "is opted out" in response_lower:
        return NOTIFICATION_PERMANENT_FAILURE
    elif "unknown error" in response_lower:
        return NOTIFICATION_TECHNICAL_FAILURE
    elif "exceed max price" in response_lower:
        return NOTIFICATION_TECHNICAL_FAILURE
    elif "phone carrier is currently unreachable/unavailable" in response_lower:
        return NOTIFICATION_TEMPORARY_FAILURE
    elif "phone is currently unreachable/unavailable" in response_lower:
        return NOTIFICATION_PERMANENT_FAILURE
    else:
        return None

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the match case isn't the most terse I have seen in a language unfortunately. I hope Python improves on that. I wouldn't mind the if...elif...else. :\

current_app.logger.exception(f"Error processing Pinpoint results: {str(e)}")
self.retry(queue=QueueNames.RETRY)

return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure we need this return statement here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

Copy link
Member

@jimleroyer jimleroyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit: 🥳

@sastels sastels merged commit 3262a4a into main May 8, 2024
4 checks passed
@sastels sastels deleted the rough-in-pinpoint branch May 8, 2024 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants