



<cfcomponent hint="BusinessMaster object" output="false">
    <cffunction name="init" access="public" output="true">
        <cfset this.accountSid = "AC3e218c8f3496f2e3f95d3f9bb943f65a">
        <cfset this.authToken = "493df16db970ca6cc141768de2db7db3">
        <cfset this.twilioNumber = "+16506678425">
        <cfloop list="#structkeylist(arguments)#" index="argvar">
            
            <cfset this[argvar]=arguments[argvar]/>
        </cfloop>
        <cfreturn this />
 
    </cffunction>
    <cffunction access="public" name="sendSMS" output="false" returntype="struct">
        <cfargument name="recipientNumber" type="string" default="0" required="No">
        <cfargument name="messageBody" type="string" default="0" required="No">
        
        <cfset local.messageSent.success=false>
        <cfset local.messageSent.message="no number or message body specified">
        <cfif len(trim(arguments.recipientNumber)) and len(trim(arguments.messageBody))>
            <cfhttp url="https://api.twilio.com/2010-04-01/Accounts/#this.accountSid#/Messages.json" method="post" result="httpResponse">
                <cfhttpparam type="header" name="Authorization" value="Basic #ToBase64(this.accountSid & ":" & this.authToken)#">
                <cfhttpparam type="formfield" name="From" value="#this.twilioNumber#">
                <cfhttpparam type="formfield" name="To" value="#arguments.recipientNumber#">
                <cfhttpparam type="formfield" name="Body" value="#arguments.messageBody#">
            </cfhttp>
           
            <cfif httpResponse.status_code EQ 201>
                <cfset local.messageSent.success=true>
                <cfset local.messageSent.message="Message sent success">
            <cfelse>
                <cfset  local.validMessage = deserializeJson(httpResponse.filecontent)>
                <cfset local.messageSent.success=false>
                <cfset local.messageSent.message=validMessage.message>
            </cfif>
        </cfif>
       
       
        <cfreturn  local.messageSent>
        
    </cffunction>
</cfcomponent>