0

Twilio API / TWIML when a user responds to my text (via text) and i receive their answer to my end-point, how do i identify the sender?

at first i thought it would be the 'sid', but it is not.. I cannot find an 'conversation_id' that exists both in the 'sending' and the 'responding' that could alert my end-point who the sender is.

when i send a text from my server, the response looks like:

{ sid: 'MMf9...',
  date_created: 'Thu, 18 Aug 2016 03:24:50 +0000',
  date_updated: 'Thu, 18 Aug 2016 03:24:50 +0000',
  date_sent: null,
  account_sid: '...',
  to: '...,
  from: '...',
  messaging_service_sid: '...',
  body: 'Hi. this is an anonymous text from my server',
  status: 'accepted',
  num_segments: '1',
  num_media: '1',
  direction: 'outbound-api',
  api_version: '2010-04-01',
  price: null,
  price_unit: null,
  error_code: null,
  error_message: null,
  uri: '/2010-04-01/Accounts/...../Messages/......json',
  subresource_uris: { media: '/2010-04-01/Accounts/...../Messages/...../Media.json' },
  dateCreated: Thu Aug 18 2016 03:24:50 GMT+0000 (UTC),
  dateUpdated: Thu Aug 18 2016 03:24:50 GMT+0000 (UTC),
  dateSent: null,
  accountSid: '....',
  messagingServiceSid: '.....',
  numSegments: '1',
  numMedia: '1',
  apiVersion: '2010-04-01',
  priceUnit: null,
  errorCode: null,
  errorMessage: null,
  subresourceUris: { media: '/2010-04-01/Accounts/..../Messages/..../Media.json' } }

When I respond with a text from my phone back to my server, my end-point receives...

{
  "ToCountry": "US",
  "ToState": "IL",
  "SmsMessageSid": "SMe....",
  "NumMedia": "0",
  "ToCity": "Chicago",
  "FromZip": "60626",
  "SmsSid": "SMe....",
  "FromState": "IL",
  "SmsStatus": "received",
  "FromCity": "CHICAGO",
  "Body": "Try",
  "FromCountry": "US",
  "To": "....",
  "MessagingServiceSid": "....",
  "ToZip": "",
  "NumSegments": "1",
  "MessageSid": "SMe...",
  "AccountSid": "...",
  "From": "...",
  "ApiVersion": "2010-04-01"
}

as you can see the sid in the original sms starts with MMf9... and all the ids in my phone's response start with SMe...

I was hoping for some conversation-id in the sending and responding would be there so that on my end-point, i could create a database entry for the conversation, and store the response of my user from the conversation. But now since there is no conversation_id between sender & receiver, I have no idea where to store the conversation and i have no idea who my server is sending responses to.

user1709076
  • 2,538
  • 9
  • 38
  • 59

1 Answers1

1

since i get the 'to' phone number in the twilio meta-data, that is a way to identify the user.

Since Twilio does let you add custom 'meta-data' to the text message the user would need to respond with extra text in the text message itself to identify the 'conversation', for example:

'John, do you think the winner should be: A, B or C? Add your voter-id to the response: 43z'

Then the user would need to text back: B 43z.

You end-point would identify the answer 'B', and '43z' would identify the respondent as 'John' (supposing you have a database look-up mapping John to 43z on your sever).

Then you can get a total count for who the winner should be, and also know each user's response for the conversation.

user1709076
  • 2,538
  • 9
  • 38
  • 59