2016-08-08 10 views
0

TwiMLメッセージを受信するURLを設定しました。 私はしかし、私は次のようTwiMLリクエストメッセージのメディアURL

  1. MediaContentType
  2. を受け取るいけない、次のフィールド

    1. アカウントシド 2.Body 3.From 4.MessageSid 5.NumMedia

    を受け取ります

  3. MediaUrl

フィールドNumMediaの値は2ですが、MediaUrlは受信しません。

私はC#を使用しています。続き

は親切に私を導い

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; } 
} 

Twilio

から受信した要求メッセージを保持する私のクラス構造です。

答えて

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; 
    } 
} 
関連する問題