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

Add WhatsApp message sending capability to adapter and create task to call such code #287

Merged
merged 11 commits into from
Mar 1, 2022

Conversation

anthonycruzmacedo
Copy link
Contributor

@anthonycruzmacedo anthonycruzmacedo commented Feb 11, 2022

Summary

Closes #285

Add a send_whatsapp method to the adapter class to send whatsapp messages to a certain phone number. The method uses a from phone number determined by a new environment variable. For testing, this means using a testing whatsapp number provided by Twilio.

Changes

  • Add send_whatsapp method to adapter.py
  • Add a send_whatsapp task to the creators tasks file
  • Add a test endpoint to call the task with an arbitrary phone number (Won't actually send to phone numbers unless they've activated the sandbox manually)

Requests / Responses

Not included because the only endpoint is for alpha testing and will be removed shortly.

@NdibeRaymond
Copy link
Collaborator

NdibeRaymond commented Feb 13, 2022

for the purpose of consistency, this function should be path of zubhub/zubhub_backend/zubhub/creators/adapters.py as we cannot have some notification handling functions in adapters.py and others in a completely different folder.

This also makes sense because after thinking about the data model for the notifications feature, It makes sense that notifications model be tied to the creators model through a one to one field (just like PhoneNumber and Settings models) (see #284 (comment)). If this ends up being the approach that we take, then moving this function into the adapters.py file seems like the best thing to do.

@AndrewLester AndrewLester changed the title Create notifications folder in zubhub_backend/zubhub, begin implement… Add WhatsApp message sending capability to adapter and create task to call such code Feb 17, 2022
@AndrewLester AndrewLester marked this pull request as ready for review February 17, 2022 03:21
@@ -29,5 +29,8 @@
path('<uuid:pk>/toggle_follow/',
ToggleFollowAPIView.as_view(), name="toggle_follow"),
path('<uuid:pk>/remove_member/',
RemoveGroupMemberAPIView.as_view(), name="remove_member")
RemoveGroupMemberAPIView.as_view(), name="remove_member"),
path('<str:phone>/send_notification',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wondering why we have a send_notification url path. Notifications are supposed to be processed on the backend right? If you can explain the flow better so anyone not actively writing the program can understand the intent of the code better.

Copy link
Contributor

Choose a reason for hiding this comment

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

The endpoint is just there for testing the Whatsapp message sending. It won't actually be called by the frontend for sending notifications and that will be handled by the backend.

Copy link
Collaborator

Choose a reason for hiding this comment

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

ok. maybe when we are done testing it, we can remove it so we don't push it to production by mistake? it's a potential security risk. Anyone who can find out that such endpoints exist can send a raw api request to fetch all notifications in our database. Of course it is difficult imagining who might want to do such, but still it makes sense to be mindful of things like this.

@NdibeRaymond
Copy link
Collaborator

code is properly structured and follows the existing convention. Tomorrow I will pull it down into the machine and play around with it a bit more. One request, is it possible to squash your local commits into one before pushing? one or two is fine but multiple commits hurt the eye.

@ajain1921
Copy link
Contributor

code is properly structured and follows the existing convention. Tomorrow I will pull it down into the machine and play around with it a bit more. One request, is it possible to squash your local commits into one before pushing? one or two is fine but multiple commits hurt the eye.

@NdibeRaymond
Are you referring to Squashing before merging into master?

@NdibeRaymond
Copy link
Collaborator

code is properly structured and follows the existing convention. Tomorrow I will pull it down into the machine and play around with it a bit more. One request, is it possible to squash your local commits into one before pushing? one or two is fine but multiple commits hurt the eye.

@NdibeRaymond Are you referring to Squashing before merging into master?

No, squashing the commit themselves before pushing. It will require a force push since you've already pushed to github. what is does is give us a single commit here, instead of the multiple commits as they are right now.
The squashing is done with rebase

@AndrewLester
Copy link
Contributor

AndrewLester commented Feb 20, 2022

@NdibeRaymond, I believe Github has a builtin feature that allows you to do this (which Aditya was referencing) so we don't have to manually do a rebase. Next to "merge pull request," click the dropdown arrow, then click "squash and merge." You can also make this the default merge strategy in the repository settings.

While squash and merge won't alter commits to this branch, it will create only a single commit in master. This branch can then be deleted. We could certainly do the rebase on this branch, but I don't want to mess up the commit history yet incase there are any last minute changes.

@tuxology
Copy link
Member

Next to "merge pull request," click the dropdown arrow, then click "squash and merge." You can also make this the default merge strategy in the repository settings.

Yes, precisely 👍 The general idea is that if there are multiple commits in the same branch-PR, they all show up here. Even if there are multiple commits, I believe reviews can be effectively done using the Files changed tab. Then we use dropdown and squash and merge.

The reasoning behind squashing is that each PR is a single state in the application's history that "works" And that state is linked to a single commit. In case something catastrophically fails in the PR, we can revert a single commit even from CLI and save the day. Else we may be spending most of time drinking ☕ and git bisecting 😉

@AndrewLester
Copy link
Contributor

Yes, precisely 👍 The general idea is that if there are multiple commits in the same branch-PR, they all show up here. Even if there are multiple commits, I believe reviews can be effectively done using the Files changed tab. Then we use dropdown and squash and merge.

The reasoning behind squashing is that each PR is a single state in the application's history that "works" And that state is linked to a single commit. In case something catastrophically fails in the PR, we can revert a single commit even from CLI and save the day. Else we may be spending most of time drinking ☕ and git bisecting 😉

Sounds good. If I'm not misunderstanding, there's no need for us to manually squash our commits with a rebase right? Since you'll take care of this squashing in the actual merge step. Then, this branch can be deleted and, along with it, the commits we made to the branch.

@@ -514,3 +515,10 @@ def create(self, request, *args, **kwargs):
{"text": text, "profile_username": result.username, "creator": request.user.username})

return Response(CreatorSerializer(result).data, status=status.HTTP_201_CREATED)


class SendNotificationAPIView(APIView):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I forgot to mention but since notifications are computed on the backend, I don't think there is a need for this view and it's associated endpoint. You can store the code snippet somewhere on your local machine to be used when we start integrating the notification stuff fully, or you might still leave it here for now for testing purposes, but ultimately I think it will probably be removed by the time the notification feature is up and running

@ajain1921 ajain1921 changed the base branch from master to notification_feature March 1, 2022 02:54
@ajain1921 ajain1921 merged commit 6e45725 into notification_feature Mar 1, 2022
@tuxology tuxology deleted the al-acm/whatsapp-twilio branch September 29, 2023 00:02
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.

Experiment with Whatsapp Twilio API
5 participants