Body return as empty string when calling messages.create with contentSid and messagingServiceSid
Overview of the Issue
When sending a message using contentSid, the response from messages.create() behaves differently depending on whether messagingServiceSid is included in the request.
Behavior without messagingServiceSid
- The response contains the expected
bodyfield with the rendered message.
Behavior with messagingServiceSid
- The response always returns an empty string (
"") for thebodyfield.
This inconsistency makes it difficult to log or validate sent messages when using contentSid with a messaging service.
Motivation for or Use Case
To ensure message logging and validation work consistently regardless of whether a messaging service is used.
twilio-node Version(s)
- Twilio SDK:
5.5.1
Operating System
-
Node.js version:
20
Edit Note:
This message was updated after discovering that the issue specifically occurs when messagingServiceSid is included in the request.
This seems to be a problem with messaging service, I have raised the issue with the concerned backend team.
Thanks for your response! Is there any update on this? @manisha1997
Hello! I tried to reproduce the issue but I am able to receive the correct body in my case. I'll share my steps here:
- I created a Content template of type "twilio/text" with a body saying "text body"
- I used the Sid of above generated content to be used as ContentSid
- I used the following code to create the message:
import twilio from 'twilio';
const accountSid: string = process.env.TWILIO_ACCOUNT_SID || "";
const token: string = process.env.TWILIO_AUTH_TOKEN || "";
const receiverPhoneNumber: string = process.env.RECEIVER_PHONE_NUMBER || "";
const client = twilio(accountSid, token);
const messagingServiceSid: string = "MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
const contentSid: string = "HXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
client.messages.create({
to: receiverPhoneNumber,
messagingServiceSid: messagingServiceSid,
contentSid: contentSid
});
- This code executes successfully and I receive a SMS in my receiverPhoneNumber saying "text body" (same body as expected).
Please check these steps once and feel free to share details if we are missing something. Thanks!
@tiwarishubham635 Thanks you for your answer!
import twilio from 'twilio';
const accountSid: string = process.env.TWILIO_ACCOUNT_SID || "";
const token: string = process.env.TWILIO_AUTH_TOKEN || "";
const receiverPhoneNumber: string = process.env.RECEIVER_PHONE_NUMBER || "";
const client = twilio(accountSid, token);
const messagingServiceSid: string = "MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
const contentSid: string = "HXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
const result = client.messages.create({
to: receiverPhoneNumber,
messagingServiceSid: messagingServiceSid,
contentSid: contentSid
});
console.log(result.body); // Logs an empyty string
The issue is not that the whatsapp arrives at a phone without body. The issue it that the return value of message.create does not contain the body. (See the example above)
We would expect it to log the body that is related to the the contentSid
Yeah this issue exists even when cURL request is made. Since this is not an issue with the SDK, we will close this issue and you can report it at https://help.twilio.com/. Thanks!