-
Notifications
You must be signed in to change notification settings - Fork 71
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
tweak in whatsapp handler on sendWhatsAppMsg returned wppID #437
tweak in whatsapp handler on sendWhatsAppMsg returned wppID #437
Conversation
@@ -1025,6 +1026,10 @@ func sendWhatsAppMsg(rc redis.Conn, msg courier.Msg, sendPath *url.URL, payload | |||
return wppID, externalID, []*courier.ChannelLog{log, checkLog, retryLog}, err | |||
} | |||
externalID, err := getSendWhatsAppMsgId(rr) | |||
wppID, err := jsonparser.GetString(rr.Body, "contacts", "[0]", "wa_id") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't do this if err != nil
from line above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very important, thanks.
Codecov Report
@@ Coverage Diff @@
## main #437 +/- ##
==========================================
- Coverage 72.08% 72.07% -0.02%
==========================================
Files 95 95
Lines 12095 12108 +13
==========================================
+ Hits 8719 8727 +8
- Misses 2773 2778 +5
Partials 603 603
Continue to review full report at Codecov.
|
Any suggestions on how to increase coverage? |
handlers/whatsapp/whatsapp_test.go
Outdated
RequestBody: `{"to":"250788123123","type":"text","text":{"body":"Simple Message"}}`, | ||
SendPrep: setSendURL}, | ||
{Label: "Unicode Send", | ||
Text: "☺", URN: "whatsapp:250788123123", | ||
Status: "W", ExternalID: "157b5e14568e8", | ||
ResponseBody: `{ "messages": [{"id": "157b5e14568e8"}] }`, ResponseStatus: 201, | ||
ResponseBody: `{ "contacts":[{"input":"250788123123","wa_id":"250788123123"}], "messages": [{"id": "157b5e14568e8"}] }`, ResponseStatus: 201, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently in our logs I see the responses we get are
{"messages":[{"id":"gBGHI0gDaJdFfwIJIN2QOPc_Il5D"}],"meta":{"api_status":"stable","version":"2.37.2"}}
So we should not change these existing tests to have the contacts
"contacts":[{"input":"250788123123","wa_id":"250788123123"}],
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, thank you.
This is a fix to update the contact URN if the wa_id returned in the send message request is different from the current URN path, avoiding creating a new contact.
I believe this is necessary in the following scenario.
Imagine a flow asking for the contact's whatsapp number through another channel type, as soon as the contact enters the number the flow sends a whatsapp template message to the contact successfully and the contact responds instantly.
If the whatsapp number is a valid phone number and whatsapp api accept the request but the wa_id is not the same as the number(as I mentioned here #433), this will generate a new contact when the contact replies to the template message, thus "breaking" the flow for the initial contact.