DataFlex
DataFlex
Twilio Send MMS (using Chilkat HTTP)
See more Twilio Examples
Send an outgoing MMS message. The only difference with MMS (as compared with SMS) is that a MediaUrl parameter is added to the POST. This means your image must be accessible on the web -- the Twilio server must be able to download the image from the URL you provide to include it in the MMS mesage to be sent.Also, see Twilio MMS for more information about MMS.
Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoHttp
Variant vReq
Handle hoReq
Variant vResp
Handle hoResp
Variant vSbResponseBody
Handle hoSbResponseBody
Handle hoJResp
Integer iRespStatusCode
Variant vDate_created
Handle hoDate_created
Variant vDate_updated
Handle hoDate_updated
Variant vDate_sent
Handle hoDate_sent
String sSid
String sAccount_sid
String sV_to
String sFrom
String sMessaging_service_sid
String sBody
String sStatus
String sNum_segments
String sNum_media
String sDirection
String sApi_version
String sPrice
String sPrice_unit
String sError_code
String sError_message
String sUri
String sSubresource_urisMedia
String sTemp1
Move False To iSuccess
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Get Create (RefClass(cComChilkatHttp)) To hoHttp
If (Not(IsComObjectCreated(hoHttp))) Begin
Send CreateComObject of hoHttp
End
// Implements the following CURL command:
// (See information about using test credentials and phone numbers: https://www.twilio.com/docs/iam/test-credentials)
// curl -X POST https://api.twilio.com/2010-04-01/Accounts/TWILIO_ACCOUNT_SID/Messages.json \
// --data-urlencode "From=+15005550006" \
// --data-urlencode "Body=body" \
// --data-urlencode "To=+15005551212" \
// -u TWILIO_ACCOUNT_SID:TWILIO_AUTH_TOKEN
// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code
Set ComLogin Of hoHttp To "TWILIO_ACCOUNT_SID"
Set ComPassword Of hoHttp To "TWILIO_AUTH_TOKEN"
Get Create (RefClass(cComChilkatHttpRequest)) To hoReq
If (Not(IsComObjectCreated(hoReq))) Begin
Send CreateComObject of hoReq
End
Set ComHttpVerb Of hoReq To "POST"
Set ComPath Of hoReq To "/2010-04-01/Accounts/TWILIO_ACCOUNT_SID/Messages.json"
Set ComContentType Of hoReq To "application/x-www-form-urlencoded"
Send ComAddParam To hoReq "From" "+15005550006"
Send ComAddParam To hoReq "Body" "body"
Send ComAddParam To hoReq "To" "+15005551212"
Send ComAddParam To hoReq "MediaUrl" "https://www.chilkatsoft.com/images/starfish.jpg"
Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
If (Not(IsComObjectCreated(hoResp))) Begin
Send CreateComObject of hoResp
End
Get pvComObject of hoReq to vReq
Get pvComObject of hoResp to vResp
Get ComHttpReq Of hoHttp "https://api.twilio.com/2010-04-01/Accounts/TWILIO_ACCOUNT_SID/Messages.json" vReq vResp To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoHttp To sTemp1
Showln sTemp1
Procedure_Return
End
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
Send CreateComObject of hoSbResponseBody
End
Get pvComObject of hoSbResponseBody to vSbResponseBody
Get ComGetBodySb Of hoResp vSbResponseBody To iSuccess
Get Create (RefClass(cComChilkatJsonObject)) To hoJResp
If (Not(IsComObjectCreated(hoJResp))) Begin
Send CreateComObject of hoJResp
End
Get pvComObject of hoSbResponseBody to vSbResponseBody
Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess
Set ComEmitCompact Of hoJResp To False
Showln "Response Body:"
Get ComEmit Of hoJResp To sTemp1
Showln sTemp1
// A 201 status code indicates success.
Get ComStatusCode Of hoResp To iRespStatusCode
Showln "Response Status Code = " iRespStatusCode
If (iRespStatusCode >= 400) Begin
Showln "Response Header:"
Get ComHeader Of hoResp To sTemp1
Showln sTemp1
Showln "Failed."
Procedure_Return
End
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "sid": "SM477111c301794f14b11eca5eefd5c350",
// "date_created": "Tue, 18 Aug 2020 15:04:47 +0000",
// "date_updated": "Tue, 18 Aug 2020 15:04:47 +0000",
// "date_sent": null,
// "account_sid": "AC2e9b6bc0f51133df24926f07341d3824",
// "to": "+15005551212",
// "from": "+15005550006",
// "messaging_service_sid": null,
// "body": "body",
// "status": "queued",
// "num_segments": "1",
// "num_media": "0",
// "direction": "outbound-api",
// "api_version": "2010-04-01",
// "price": null,
// "price_unit": "USD",
// "error_code": null,
// "error_message": null,
// "uri": "/2010-04-01/Accounts/AC2e9b6bc0f51133df24926f07341d3824/Messages/SM477111c301794f14b11eca5eefd5c350.json",
// "subresource_uris": {
// "media": "/2010-04-01/Accounts/AC2e9b6bc0f51133df24926f07341d3824/Messages/SM477111c301794f14b11eca5eefd5c350/Media.json"
// }
// }
// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
Get Create (RefClass(cComChilkatDtObj)) To hoDate_created
If (Not(IsComObjectCreated(hoDate_created))) Begin
Send CreateComObject of hoDate_created
End
Get Create (RefClass(cComChilkatDtObj)) To hoDate_updated
If (Not(IsComObjectCreated(hoDate_updated))) Begin
Send CreateComObject of hoDate_updated
End
Get Create (RefClass(cComChilkatDtObj)) To hoDate_sent
If (Not(IsComObjectCreated(hoDate_sent))) Begin
Send CreateComObject of hoDate_sent
End
Get ComStringOf Of hoJResp "sid" To sSid
Get pvComObject of hoDate_created to vDate_created
Get ComDtOf Of hoJResp "date_created" False vDate_created To iSuccess
Get pvComObject of hoDate_updated to vDate_updated
Get ComDtOf Of hoJResp "date_updated" False vDate_updated To iSuccess
Get pvComObject of hoDate_sent to vDate_sent
Get ComDtOf Of hoJResp "date_sent" False vDate_sent To iSuccess
Get ComStringOf Of hoJResp "account_sid" To sAccount_sid
Get ComStringOf Of hoJResp "to" To sV_to
Get ComStringOf Of hoJResp "from" To sFrom
Get ComStringOf Of hoJResp "messaging_service_sid" To sMessaging_service_sid
Get ComStringOf Of hoJResp "body" To sBody
Get ComStringOf Of hoJResp "status" To sStatus
Get ComStringOf Of hoJResp "num_segments" To sNum_segments
Get ComStringOf Of hoJResp "num_media" To sNum_media
Get ComStringOf Of hoJResp "direction" To sDirection
Get ComStringOf Of hoJResp "api_version" To sApi_version
Get ComStringOf Of hoJResp "price" To sPrice
Get ComStringOf Of hoJResp "price_unit" To sPrice_unit
Get ComStringOf Of hoJResp "error_code" To sError_code
Get ComStringOf Of hoJResp "error_message" To sError_message
Get ComStringOf Of hoJResp "uri" To sUri
Get ComStringOf Of hoJResp "subresource_uris.media" To sSubresource_urisMedia
End_Procedure