我如何为我的 twilio 端点和发短信给我的端点的人之间的对话获得唯一的 'id'

How do i get a unique 'id' for my conversation between my twilio end-point and the person texting to my end-point

Twilio API / TWIML 当用户回复我的文本(通过文本)并且我收到他们对我的终点的答复时,我如何识别发件人?

一开始我以为是 'sid',但不是.. 我找不到同时存在于 'sending' 和 [=28= 中的 'conversation_id' ] 这可以提醒我的端点发件人是谁。

当我从我的服务器发送文本时,响应如下:

{ 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' } }

当我用来自 phone 的文本回复到我的服务器时,我的端点收到...

{
  "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"
}

如您所见,原始短信中的 sid 以 MMf9 开头...而我的 phone 回复中的所有 id 均以 SMe 开头...

我希望在发送和响应中有一些对话 ID,以便在我的端点上,我可以为对话创建一个数据库条目,并存储我的用户从对话中得到的响应。但是现在由于发送者和接收者之间没有 conversation_id,我不知道在哪里存储对话,也不知道我的服务器正在向谁发送响应。

因为我在 twilio 元数据中得到 'to' phone 数字,这是一种识别用户的方法。

由于 Twilio 确实允许您将自定义 'meta-data' 添加到短信中,因此用户需要在短信本身中使用额外的文本进行响应以识别 'conversation',例如:

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

然后用户需要回短信:B 43z。

您的终点将识别答案 'B',而“43z”会将受访者识别为 'John'(假设您的服务器上有一个将 John 映射到 43z 的数据库查找) .

然后您可以获得获胜者的总数,还可以知道每个用户对对话的回应。