Skip to content

STRATCONN-6815 - [Twilio Messaging] - String if non string payload values#3794

Open
joe-ayoub-segment wants to merge 2 commits into
mainfrom
twilio-messaging-bugfix
Open

STRATCONN-6815 - [Twilio Messaging] - String if non string payload values#3794
joe-ayoub-segment wants to merge 2 commits into
mainfrom
twilio-messaging-bugfix

Conversation

@joe-ayoub-segment
Copy link
Copy Markdown
Contributor

@joe-ayoub-segment joe-ayoub-segment commented May 15, 2026

  • Fixes Twilio error 21656 by stringifying ContentVariables values (numbers, booleans) before sending to the Twilio API, which requires all template variable values to be strings
  • Gated behind feature flag twilio-messaging-stringify-content-variables for safe rollout

Testing

  • Added test verifying non-string ContentVariables values (numbers, booleans) are stringified when flag is enabled
  • All 55 existing Twilio Messaging tests continue to pass

Tested locally - but sent to production twilio - which sent an SMS with the correct values.

See video for full test walkthrough. https://drive.google.com/file/d/1ULAU6TMb3yZUltXSUwy5y6yAUIwkjw7Z/view?usp=sharing

joe mobile test with bool and numbers

Security Review

Please ensure sensitive data is properly protected in your integration.

  • Reviewed all field definitions for sensitive data (API keys, tokens, passwords, client secrets) and confirmed they use type: 'password'

New Destination Checklist

  • Extracted all action API versions to verioning-info.ts file. example

Copilot AI review requested due to automatic review settings May 15, 2026 12:35
@joe-ayoub-segment joe-ayoub-segment requested a review from a team as a code owner May 15, 2026 12:35
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Ensures Twilio Messaging “ContentVariables” values are sent as strings by coercing non-string values prior to JSON encoding, and adds a regression test to verify the new behavior for numeric/boolean inputs.

Changes:

  • Stringifies contentVariables values before setting ContentVariables in the Twilio payload.
  • Adds a unit test asserting the outbound encoded request body contains stringified ContentVariables.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
packages/destination-actions/src/destinations/twilio-messaging/sendMessage/utils.ts Coerces contentVariables values to strings before JSON encoding into ContentVariables.
packages/destination-actions/src/destinations/twilio-messaging/sendMessage/__tests__/index.test.ts Adds a test validating non-string contentVariables (numbers/booleans) are stringified in the request body.

Comment on lines +98 to +102
if (Object.keys(contentVariables ?? {}).length > 0) {
contentTemplate.ContentVariables = JSON.stringify(contentVariables)
const stringified = Object.fromEntries(
Object.entries(contentVariables ?? {}).map(([k, v]) => [k, String(v)])
)
contentTemplate.ContentVariables = JSON.stringify(stringified)
Comment on lines +232 to +235
const expectedBody = 'To=%2B1234567890&MessagingServiceSid=MG1234567890abcdef1234567890abcdef&ContentSid=HX1234567890abcdef1234567890abcdef&ContentVariables=%7B%22amount_to_finance%22%3A%2212899%22%2C%22cash_price%22%3A%2212500%22%2C%22monthly_payment%22%3A%22285.28%22%2C%22term%22%3A%2260%22%2C%22is_approved%22%3A%22true%22%2C%22vehicle%22%3A%22500+Mhev%22%7D'

nock('https://api.twilio.com')
.post(`/2010-04-01/Accounts/${defaultSettings.accountSID}/Messages.json`, expectedBody)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants