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 support for sending Twilio Template #751

Merged
merged 1 commit into from
Jun 3, 2024
Merged

Conversation

norkans7
Copy link
Contributor

No description provided.

Copy link

codecov bot commented May 30, 2024

Codecov Report

Attention: Patch coverage is 87.09677% with 8 lines in your changes are missing coverage. Please review.

Project coverage is 75.84%. Comparing base (43f290b) to head (065b45b).

Files Patch % Lines
handlers/twiml/handlers.go 87.09% 4 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #751      +/-   ##
==========================================
+ Coverage   75.81%   75.84%   +0.03%     
==========================================
  Files         111      111              
  Lines       10316    10363      +47     
==========================================
+ Hits         7821     7860      +39     
- Misses       1781     1785       +4     
- Partials      714      718       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@norkans7 norkans7 requested a review from rowanseymour May 30, 2024 17:27
@norkans7 norkans7 marked this pull request as ready for review May 30, 2024 17:27
// do we have a template and support whatsapp scheme?
if msg.Templating() != nil && channel.IsScheme(urns.WhatsApp) {
if msg.Templating().ExternalID == "" {
return courier.ErrFailedWithReason("", "template missing contentSID")
Copy link
Member

Choose a reason for hiding this comment

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

again ErrFailedWithReason is for error codes from the channel side that we can expose on the RP side

If the scenario above happens, it's because we've messed up syncing templates or creating messages in mailroom. Therefore it's something that courier shouldn't retry and should log. In that way it's similar to ErrChannelConfig but how about we add a new err type for this....

// ErrMessageInvalid should be returned by a handler send method when the message it has received is invalid
var ErrMessageInvalid error = &SendError{
	msg:       "message invalid",
	retryable: false,
	loggable:  true,
	clogCode:  "message_invalid",
	clogMsg:   "Message is missing required values.",
}

form.Add("MediaUrl", a.URL)
}
}
contentVariables := make(map[string]string)
Copy link
Member

Choose a reason for hiding this comment

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

make(map[string]string, len(msg.Templating().Variables))

if channel.IsScheme(urns.WhatsApp) {
form["To"][0] = fmt.Sprintf("%s:+%s", urns.WhatsApp.Prefix, form["To"][0])
form["From"][0] = fmt.Sprintf("%s:%s", urns.WhatsApp.Prefix, form["From"][0])
contentVariablesJson, _ := json.Marshal(contentVariables)
Copy link
Member

Choose a reason for hiding this comment

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

if you're not checking the error, and there's no reason to here because there's nothing we're marshaling here that could fail to marshal, use jsonx.MustMarshal

sort.Strings(varNames)
for _, varName := range varNames {
contentVariables[varName] = msg.Templating().Variables[comp.Variables[varName]].Value
}
Copy link
Member

Choose a reason for hiding this comment

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

can't this be a bit simpler like

for _, comp := range msg.Templating().Components {
	for varVey, varIndex := range comp.Variables {
		contentVariables[varKey] = msg.Templating().Variables[varIndex]
	}
}

I'm not getting why you need a sort...

// do we have a template and support whatsapp scheme?
if msg.Templating() != nil && channel.IsScheme(urns.WhatsApp) {
if msg.Templating().ExternalID == "" {
return courier.ErrMessageInvalid
Copy link
Member

Choose a reason for hiding this comment

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

@norkans7 please have a think about places in other handlers where we should use this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes

@rowanseymour rowanseymour merged commit c6be0bc into main Jun 3, 2024
7 checks passed
@rowanseymour rowanseymour deleted the TWA-templates branch June 3, 2024 17:56
@github-actions github-actions bot locked and limited conversation to collaborators Jun 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants