2016-08-08 15 views
0

Ich habe eine URL konfiguriert, um TwiML-Nachricht zu empfangen. Ich erhalte folgende FelderMedien-URL in TwiML-Anforderungsnachricht

  1. Konto Sid 2.Body 3.From 4.MessageSid 5.NumMedia

Allerdings erhalte ich nicht die folgenden

  1. MediaContentType
  2. MediaUrl

Obwohl das Feld NumMedia den Wert 2 hat, empfange ich MediaUrl nicht.

Ich benutze C#.

Folgende ist meine Klassenstruktur, die die Anforderungsnachricht von 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; } 
} 

Bitte führen Sie mich empfangen wird halten.

Antwort

1

Wenn die MMS-Nachricht empfangen wird und Medien (Bilder, Videos) enthält, wird die Zahl tatsächlich in das Feld NumMedia der POST-Anfrage, die an Ihren Server gerichtet ist, abgelegt. Die einzelnen Medien URLs und Identifikator werden ihre aufeinanderfolgenden Sequenznummern angehängt werden (bis zu 10), und dass in der POST-Anforderung mit vielen einzelnen Feldern, die jeweils für den Medieninhalt führen würde:

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

Bei Erfassung der Medien in der die POST-Anfrage (! = 0 NumMedia) sollten Sie über die Felder zu retrieve interesting arguments iterieren.

finden Sie unter Beispielimplementierung:

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