Scripts 3/3
Script 1: SMS Monitor
(Temporary Scripts from Chimerical. Replace in the future.)
IF Test = 1
{
PhoneNum = "18013805656"
message = "Test from Studio"
}
// The recipient ofthe SMS, must be 11 digits
SMSPhoneNum = "{PhoneNum}"
// MMS Configuration
AccessKey = "MTAwOTIzNjQ5MDoxMDhDQUMyRTc1"
TransportCode = 13852184959
Key = "30fa465b-5c6c-4f22-90b3-c06a30a4939d"
URI = "https://ic.mms.us/icsm/api/sendmsg/Send"
textmsg = "Thank you for contacting Delta Defense. Please provide your age."
URIparams = "<?xml version='1.0' encoding='UTF-8'?>"
URIparams.append("<SendMessageRequest>")
URIparams.append("<phone>{SMSPhoneNum}</phone>")
URIparams.append("<key>{key}</key>")
URIparams.append("<tc>{TransportCode}</tc>")
URIparams.append("<message><![CDATA[{textmsg}]]></message>")
URIparams.append("</SendMessageRequest>")
//Create a REST Proxy
Proxy=GetRESTProxy()
//Authorization
Auth = "Basic {AccessKey}"
Proxy.AddHeader("Authorization", Auth)
//Send message
SendResult=Proxy.MakeRestRequest("{URI}", "{URIParams}", 1, "POST")
//for testing in studio
IF test = 1
{
contactID = 123456798
}
ASSIGN userName="jw.se@b2.com"
ASSIGN password="SEpass1234"
ASSIGN securityToken="NjHbx7PPIvYS8wJDdRj2r0NV"
ASSIGN consumerKey="3MVG9xOCXq4ID1uHDQQBfP6_Fo8b_csjoZxREsAflcHg9fOHSJiShsaid11SHhNP13etxCp8ft81Z.ByO5dkx"
ASSIGN consumerSecret="5350160340401136582"
// Setup a Salesforce Proxy for the SF access token
ASSIGN tokenproxy = GetRESTProxy()
// urlencode the login credentials and the security token since we are putting them
// on the URL as parameters
ASSIGN password=password.urlencode
ASSIGN userName=userName.urlencode
ASSIGN securityToken=securityToken.urldecode
ASSIGN consumerKey=consumerKey.urlencode
ASSIGN consumerSecret=consumerSecret.urlencode
// create the token request parameters string, and the URL string
tokenRequestParams=""
tokenRequestParams.append("grant_type=password")
tokenRequestParams.append("&client_id={consumerKey}")
tokenRequestParams.append("&client_secret={consumerSecret}")
tokenRequestParams.append("&username={userName}")
tokenRequestParams.append("&password={password}{securityToken}")
// create a tokenRequestURL based on whether this is a production or sandbox envirnment
ASSIGN tokenRequestURL="https://login.salesforce.com/services/oauth2/token"
// get the security token.
ASSIGN tokenResult=tokenproxy.MakeRestRequest(tokenRequestURL, tokenRequestParams, 0, "POST")
ASSIGN myToken=tokenResult.access_token.$value
// create base URL of Salesforce instance
ASSIGN baseURL = tokenResult.instance_url.$value
//create query URL
ASSIGN queryURL = "{baseURL}/services/data/v20.0/query"
// Create update URL
ASSIGN updateURL = "{baseURL}/services/data/v20.0/sobjects/Lead/"
// create access token
ASSIGN accessToken="Bearer "
accessToken.append("{myToken}")
tokenProxy.AddHeader("Authorization",accessToken)
tokenProxy.ContentType = "application/json"
//Create new Case object in SFDC
DYNAMIC myLead
ASSIGN myLead.LastName="{messageContent}"
ASSIGN myLead.Company="Undetermined"
ASSIGN myLead.Phone="{phoneNum}"
ASSIGN myLead.Description="{pNum[2]}"
// ASSIGN myLead.Subject="New Case - {now}"
// ASSIGN myLead.ContactID__c="{ContactID}"
//ASSIGN myLead.CallType="Inbound"
ASSIGN json = "{myLead.AsJson()}"
// Send to SalesForce for Case creation
ASSIGN leadResult = tokenproxy.MakeRestRequest(updateURL, json, 0, "POST")
// Retrieve Case ID
ASSIGN myLeadID = leadResult.id.$value
IF Test = 1
{
PhoneNum = "18019990199"
message = "Test from Studio"
}
// The recipient ofthe SMS, must be 11 digits
SMSPhoneNum = "{PhoneNum}"
// MMS Configuration
AccessKey = "SW5Db250YWN0OmI1YjViOWRlLWFjNmMtNDk3ZS1iMjBhLWE3OGRjMWU5OGNkYg=="
TransportCode = 13852184959
Key = "0da3292d-d5df-4612-b4cb-4168893d12d6"
URI = "https://ic.mms.us/icsm/api/sendmsg/Send"
textmsg = "Thank you for contacting roadside assistance. Please provide your 5-digit Zip Code where you require assistance."
URIparams = "<?xml version='1.0' encoding='UTF-8'?>"
URIparams.append("<SendMessageRequest>")
URIparams.append("<phone>{SMSPhoneNum}</phone>")
URIparams.append("<key>{key}</key>")
URIparams.append("<tc>{TransportCode}</tc>")
URIparams.append("<message><![CDATA[{textmsg}]]></message>")
URIparams.append("</SendMessageRequest>")
//Create a REST Proxy
Proxy=GetRESTProxy()
//Authorization
Auth = "Basic {AccessKey}"
Proxy.AddHeader("Authorization", Auth)
//Send message
SendResult=Proxy.MakeRestRequest("{URI}", "{URIParams}", 1, "POST")
//{
// SMSPhoneNum = "18013805656"
//}
//
//CaseCheck = "False"
//
//SFDCqueryNum = "{arrsms.substr(2,11)}"
//
//// Login credentials for NA17
//ASSIGN SFUserName="api.se@c4.com"
//ASSIGN SFPassword="inC0ntact!"
//ASSIGN SFToken="sQuu5yfLX5C4hlKWfKcocEUR4"
//
//// Specific DLL to be used
//USES "SalesforceNA17WS.dll"
//
//
//ASSIGN sforce = new SalesforceNA17WS.SforceService_NG()
//ASSIGN loginresult=sforce.login("{SFUserName}","{SFPassword}{SFToken}")
//ASSIGN sforce.Url = loginResult.serverUrl
//
//ASSIGN session = new SalesforceNA17WS.SessionHeader()
//ASSIGN session.sessionId = loginResult.sessionId
//ASSIGN sforce.SessionHeaderValue = session
//ASSIGN sessionId = loginResult.sessionId
//
//
// ASSIGN url = sforce.url
// ASSIGN periodLoc = url.indexof(".")
// ASSIGN SFserver = url.substr(1,periodLoc)
// ASSIGN baseURL = "{SFserver}salesforce.com"
//
// ASSIGN contactQueryResult = sforce.query("SELECT id, Name, Phone FROM Contact WHERE Phone LIKE '%{SFDCqueryNum.substr(1,3)}%{SFDCqueryNum.substr(4,6)}%{SFDCqueryNum.substr(7,10)}' order by createdDate LIMIT 1")
// ASSIGN resultCount = contactQueryResult.size
//
// IF resultCount > 0
// {
// ASSIGN myContact = contactQueryResult.records
// ASSIGN myContactName=(myContact[1] as SalesforceNA17WS.Contact).Name
// ASSIGN myContactID=(myContact[1] as SalesforceNA17WS.Contact).id
// }
//
//
// ASSIGN userName="jw.se@b2.com"
// ASSIGN password="SEpass1234"
// ASSIGN securityToken="NjHbx7PPIvYS8wJDdRj2r0NV"
//
//
// ASSIGN consumerKey="3MVG9xOCXq4ID1uHDQQBfP6_Fo8b_csjoZxREsAflcHg9fOHSJiShsaid11SHhNP13etxCp8ft81Z.ByO5dkx"
// ASSIGN consumerSecret="5350160340401136582"
//
//
//
// // Setup a Salesforce Proxy for the SF access token
// ASSIGN tokenproxy = GetRESTProxy()
//
// // urlencode the login credentials and the security token since we are putting them
// // on the URL as parameters
// ASSIGN password=password.urlencode
// ASSIGN userName=userName.urlencode
// ASSIGN securityToken=securityToken.urldecode
// ASSIGN consumerKey=consumerKey.urlencode
// ASSIGN consumerSecret=consumerSecret.urlencode
//
// // create the token request parameters string, and the URL string
// tokenRequestParams=""
// tokenRequestParams.append("grant_type=password")
// tokenRequestParams.append("&client_id={consumerKey}")
// tokenRequestParams.append("&client_secret={consumerSecret}")
// tokenRequestParams.append("&username={userName}")
// tokenRequestParams.append("&password={password}{securityToken}")
//
// // create a tokenRequestURL based on whether this is a production or sandbox envirnment
// ASSIGN tokenRequestURL="https://login.salesforce.com/services/oauth2/token"
//
// // get the security token.
// ASSIGN tokenResult=tokenproxy.MakeRestRequest(tokenRequestURL, tokenRequestParams, 0, "POST")
// ASSIGN myToken=tokenResult.access_token.$value
//
// // create base URL of Salesforce instance
// ASSIGN baseURL = tokenResult.instance_url.$value
//
// //create query URL
// ASSIGN queryURL = "{baseURL}/services/data/v20.0/query"
//
// // Create update URL
// ASSIGN updateURL = "{baseURL}/services/data/v20.0/sobjects/Case/"
//
// // create access token
// ASSIGN accessToken="Bearer "
// accessToken.append("{myToken}")
//tokenProxy.AddHeader("Authorization",accessToken)
// tokenProxy.ContentType = "application/json"
//
//
//
// //Create new Case object in SFDC
// DYNAMIC myCase
// ASSIGN myCase.Status="En Route"
// ASSIGN myCase.Subject="Refill request - {now}"
// //ASSIGN myCase.Phone="{custPhone}}"
// ASSIGN myCase.ContactID__c="{ContactID}"
// ASSIGN myCase.ContactId="{myContactID}"
// ASSIGN myCase.Origin="IVR"
//
// ASSIGN json = "{myCase.AsJson()}"
//
// // Send to SalesForce for Case creation
// ASSIGN caseResult = tokenproxy.MakeRestRequest(updateURL, json, 0, "POST")
//
// // Retrieve Case ID
// ASSIGN myCaseID = caseResult.id.$value
//
// // Retrieve Case Number
// ASSIGN caseQueryResult = sforce.query("SELECT id, casenumber FROM Case WHERE id = '{myCaseID}' order by createdDate limit 1")
//
// ASSIGN CaseCheck="True"
//
// ASSIGN CaseRecords=caseQueryResult.records
// ASSIGN myCaseNumber=(CaseRecords[1] as SalesforceNA17WS.CASE).CaseNumber
//
//
//IF CaseCheck="True"
//{
// popURL = "https://na17.salesforce.com/{myCaseID}"
//}
//ELSE
//{
// popURL = "https://na17.salesforce.com/500/e" //Open case creation window
//}
//
//
//
IF Test = 1
{
PhoneNum = "18019990199"
message = "Test from Studio"
}
// The recipient ofthe SMS, must be 11 digits
SMSPhoneNum = "{PhoneNum}"
// MMS Configuration
AccessKey = "SW5Db250YWN0OmI1YjViOWRlLWFjNmMtNDk3ZS1iMjBhLWE3OGRjMWU5OGNkYg=="
TransportCode = 13852184959
Key = "0da3292d-d5df-4612-b4cb-4168893d12d6"
URI = "https://ic.mms.us/icsm/api/sendmsg/Send"
SWITCH messageContent
{
CASE "y"
CASE "Y"
{
textmsg = "Thank you. Your prescription is on the way. We have generated case {myCaseNumber} for this request."
}
CASE "n"
CASE "N"
{
textmsg = "Ok, we have not refilled your prescription."
}
}
URIparams = "<?xml version='1.0' encoding='UTF-8'?>"
URIparams.append("<SendMessageRequest>")
URIparams.append("<phone>{SMSPhoneNum}</phone>")
URIparams.append("<key>{key}</key>")
URIparams.append("<tc>{TransportCode}</tc>")
URIparams.append("<message><![CDATA[{textmsg}]]></message>")
URIparams.append("</SendMessageRequest>")
//Create a REST Proxy
Proxy=GetRESTProxy()
//Authorization
Auth = "Basic {AccessKey}"
Proxy.AddHeader("Authorization", Auth)
//Send message
SendResult=Proxy.MakeRestRequest("{URI}", "{URIParams}", 1, "POST")
{
PhoneNum = "18019990199"
message = "Test from Studio"
}
// The recipient ofthe SMS, must be 11 digits
SMSPhoneNum = "{PhoneNum}"
text="Thank you for contacting us today. We understand you would like to refill your prescription. Reply 'Y' for Yes or 'N' for No."
// MMS Configuration
AccessKey = "SW5Db250YWN0OmI1YjViOWRlLWFjNmMtNDk3ZS1iMjBhLWE3OGRjMWU5OGNkYg=="
TransportCode = 13852184959
Key = "0da3292d-d5df-4612-b4cb-4168893d12d6"
URI = "https://ic.mms.us/icsm/api/sendmsg/Send"
Message = "<![CDATA[{text}]]>"
Params = "<?xml version='1.0' encoding='UTF-8'?><SendMessageRequest><phone>{SMSPhoneNum}</phone><key>{Key}</key><tc>{TransportCode}</tc><message>{Message}</message></SendMessageRequest>"
//Create a REST Proxy
ASSIGN Rest=GetRESTProxy()
//Authorization
ASSIGN Auth = "Basic {AccessKey}"
Rest.AddHeader("Authorization", Auth)
//Make request
ASSIGN Result=Rest.MakeRestRequest("{URI}", "{Params}", 1, "POST")