TwiML请求消息中的媒体Url
本文关键字:媒体 Url 请求 消息 TwiML | 更新日期: 2023-09-27 18:01:15
我已经配置了一个url来接收TwiML消息。我收到以下字段
- 账户Sid2.身体3.从4.MessageSid5.NumMedia
然而,我没有收到以下
- MediaContentType
- MediaUrl
虽然字段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; }
}
请指引我。
当MMS消息被接收并包含媒体(图像,视频)时,它确实会将计数放入指向服务器的POST请求的NumMedia
字段中。单独的媒体url和标识符将附加它们的连续序列号(最多10个),这将导致POST请求具有许多单独的字段,每个字段用于媒体内容:
"MediaContentType0" : "",
"MediaUrl0" :"",
"MediaContentType1" : "",
"MediaUrl1" :""
在POST请求中检测到媒体(!=0 NumMedia
),您应该遍历字段以检索感兴趣的参数。
请参见下面的示例实现:
// 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;
}
}