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

tweak in whatsapp handler on sendWhatsAppMsg returned wppID #437

Merged

Conversation

rasoro
Copy link
Contributor

@rasoro rasoro commented Apr 22, 2022

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.

@@ -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")
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

very important, thanks.

@codecov
Copy link

codecov bot commented Apr 22, 2022

Codecov Report

Merging #437 (373fd00) into main (5834bc2) will decrease coverage by 0.01%.
The diff coverage is 72.22%.

@@            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              
Impacted Files Coverage Δ
handlers/test.go 0.00% <0.00%> (ø)
handlers/whatsapp/whatsapp.go 78.80% <100.00%> (+0.24%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5834bc2...373fd00. Read the comment docs.

@rasoro rasoro requested a review from rowanseymour April 22, 2022 18:08
@rasoro
Copy link
Contributor Author

rasoro commented Apr 22, 2022

Any suggestions on how to increase coverage?

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,
Copy link
Contributor

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"}],

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, thank you.

@rasoro rasoro requested a review from norkans7 April 25, 2022 15:38
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.

3 participants