0

I am working on an appointment confirmation system where I need to bind the SMS response 'Y' or 'N' to some meta data and send that meta data to my API via the Twilio webhook.

I am using.NET SDK from Twilio and trying to add attributes to the SMS message (MessageResource) which their documentation states:

Attributes:

  • STRING PII MTL: 30 DAYS "The JSON string that stores application-specific data. If attributes have not been set, {} is returned."

link to docs: https://www.twilio.com/docs/chat/rest/message-resource#message-properties

which is more like metadata which is what I need but when I try finding any 'attributes' property in my C# code with their SDK I can't find it.

Here's my code:

 var twilioMessage = MessageResource.Create(
                    body: msg,
                    from: _configuration["Twilio:FromPhoneNo"],
                    to: new PhoneNumber(phoneNumber),
                    attempt:1,
                    attributes: "{"id":"test"}" //this property doesn't work
                );

  var attributes = twilioMessage.attributes; //this doesn't work either

Any help will be highly appreciated.

Zeeshan Adil
  • 1,937
  • 5
  • 23
  • 42

1 Answers1

1

Twilio developer evangelist here.

I'm afraid you are looking at the wrong documentation for sending SMS messages there. This documentation is for sending a chat (app to app) message. The documentation for sending an SMS is here.

Sadly, SMS messages do not have the ability to bind custom attributes to them. It is simply something that doesn't exist in the protocol.

You are sending an appointment confirmation and expecting a "Y" or "N" response. I am guessing you are trying to add the ID of the appointment in the case that you send confirmations for more than one appointment to the same phone number and you need to work out which appointment the response is about. There's a further issue here in that, as an end user, you cannot reply to a specific SMS messages. SMS is purely chronological.

There are 3 ways I can think of to work around this:

  1. Only send one confirmation at a time. If you are still waiting for a response to a confirmation, don't send another one until you get that response. This might not work if users don't respond to confirmations.

  2. Have the user include the ID of the appointment in the response. This is flaky because it relies on the users getting things right and you want to make things as simple as you can for them

  3. When you need to send more than one confirmation at a time, use different Twilio numbers to send the confirmations. Then you can tie the confirmation response to the appointment by inspecting the Twilio number that the user sent the message to.

Number 3 is the most sound way of doing this. It shouldn't require you to have too many extra numbers, just as many as you might have concurrent appointment confirmations.

Let me know if this helps at all.

philnash
  • 70,667
  • 10
  • 60
  • 88