【问题标题】:Media Url in TwiML request messageTwiML 请求消息中的媒体 URL
【发布时间】:2016-08-10 01:21:50
【问题描述】:

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

  1. 帐户 Sid 2.身体 3.从 4.MessageSid 5.NumMedia

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

  1. 媒体内容类型
  2. 媒体网址

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

我使用 c#。

以下是我的类结构,它将保存从 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; }
}

请指导我。

【问题讨论】:

    标签: c# twilio twilio-api


    【解决方案1】:

    当收到 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;
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-16
      • 2022-12-11
      • 1970-01-01
      • 2022-01-19
      • 2018-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多