Twillo SMS API Integration with coldfusion.
Twillo SMS Integration with coldfusion.
First create a account with twillo.com and download library and docs for help, From here you can get AccountsID and AuthToken.
Here is a example to Integration with coldfusion
I hope this is useful for you. thank you
First create a account with twillo.com and download library and docs for help, From here you can get AccountsID and AuthToken.
Here is a example to Integration with coldfusion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfoutput> | |
<cfset resourceMethod = "Post"/> | |
<cfset resourceUri="Accounts/{AccountSid}/SMS/Messages.{format}"> | |
<cfset AccountsID="xxxxxxxxxxx"> | |
<cfset AuthToken="xxxxxxxxxxxx"> | |
<cfset ApiVersion = "2010-04-01"/> | |
<cfset ApiEndpoint = "api.twilio.com"/> | |
<cfset form.format="xml"> | |
<cfset left = "<" /> | |
<cfset right = ">" /> | |
<!---- Create a Person structure ---> | |
<cfset Form=StructNew()> | |
<cfset Form.To="xxxxxxxxxxxx"> (With CountryCode) | |
<cfset Form.Body="This is Test Message Code"> | |
<cfset Form.From="xxxxxxxxxx"> (provided by Twillio) | |
<cfset Form.StatusCallBack="http://127.0.0.1:8500/Test/messagestatus.cfm"> | |
<cfloop collection="#form#" item="f"> | |
<cfif FindNoCase("{#f#}", resourceUri) AND len(trim(FORM[f]))> | |
<cfset resourceUri = ReplaceNoCase(resourceUri, "{#f#}", FORM[f]) /> | |
<cfset StructDelete(FORM, f) /> | |
</cfif> | |
<!--- Now, if any of the parameters are blank, delete them... ---> | |
<cfif StructKeyExists(FORM, f) AND NOT len(trim(FORM[f]))> | |
<cfset StructDelete(FORM, f) /> | |
</cfif> | |
</cfloop> | |
<cfdump var="#Form#"> | |
<!---Create Object of Twilio.cfc Object---> | |
<cfset TwilioLib = createObject("component", "lib.TwilioLib").init(AccountsID, AuthToken, ApiVersion, ApiEndpoint) /> | |
<!---Call newRequest function from Twilio.cfc---> | |
<cfset requestObj = TwilioLib.newRequest(ResourceUri, ResourceMethod, FORM, AccountsID, AuthToken) /> | |
<!--- <cfdump var="#requestObj#">---> | |
<h4>Request Result</h4> | |
<cfif requestObj.getResponse().wasSuccessful()> | |
Message was sent <span class="success">successful</span>. | |
<cfelse> | |
<span class="fail">Message sent failed</span>. | |
</cfif> | |
<cfdump var="#requestObj.getResponse().output()#" label="Response Output" expand="true" /> | |
</cfoutput> |
I hope this is useful for you. thank you
Comments
Post a Comment