TwiML 请求消息中的媒体 Url

Media Url in TwiML request message

我已经配置了 url 来接收 TwiML 消息。 我收到以下字段

  1. 帐户 Sid 2.Body 3.From 4.MessageSid 5.NumMedia

但是,我没有收到以下内容

  1. MediaContentType
  2. MediaUrl

尽管 NumMedia 字段的值为 2,但我没有收到 MediaUrl。

我用的是c#。

以下是我的 class 结构,它将保存从 Twilio 收到的请求消息

public class TwilioRequest
    {
        public string MessageSid { get; set; }
        public string AccountSid { get; set; }
        public string From { get; set; }
        public string To { get; set; }
        public string Body { get; set; }
        public int NumMedia { get; set; }
        public List<string> MediaContentType { get; set; }
        public List<string> MediaUrl { get; set; }
}

请指导我。

当接收到包含媒体(图像、视频)的 MMS 消息时,它确实会将计数放入针对您的服务器的 POST 请求的 NumMedia 字段中。各个媒体 url 和标识符将附加其连续的序列号(最多 10 个),这将导致 POST 请求具有许多单独的字段,每个字段用于媒体内容:

"MediaContentType0" : "",
"MediaUrl0" :"",
"MediaContentType1" : "",
"MediaUrl1" :""

在 POST 请求 (!=0 NumMedia) 中检测到媒体后,您应该将字段迭代到 retrieve interesting arguments

请参阅下面的示例实现:

// Build name value pairs for the incoming web hook from Twilio
NameValueCollection nvc = Request.Form;
// Type the name value pairs
string strFrom = nvc["From"];
string strNumMedia = nvc["NumMedia"];
string strBody = nvc["Body"];

// Holds the image type and link to the images
List<string> listMediaUrl = new List<string>();
List<string> listMediaType = new List<string>();
List<Stream> listImages = new List<

// Find if there was any multimedia content

if (int.Parse(strNumMedia) != 0) {
  // If there was find out the media type and the image url so we can pick them up
  for (int intCount = 0; intCount < int.Parse(strNumMedia);) {
    // Store the media type for the image even through they should be the same
    listMediaType.Add(nvc[("MediaContentType" + intCount).ToString()]);
    // Store the image there is a fair chance of getting more then one image Twilio supports 10 in a single MMS up to 5Mb
    listMediaUrl.Add(nvc[("MediaUrl" + intCount).ToString()]);
    // Update the loop counter
    intCount = intCount + 1;
  }
}