Skip to content

Instantly share code, notes, and snippets.

@quintonwall
Created March 16, 2019 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quintonwall/3daf22817e548a0e6e152ece962400f5 to your computer and use it in GitHub Desktop.
Save quintonwall/3daf22817e548a0e6e152ece962400f5 to your computer and use it in GitHub Desktop.
Call Twilio Survey From Swift
func sendSMSSurvey(opportunityId: String, surveyType: String, completion: @escaping DashDataCompletion) {
let data = [
"To" : "4159999999",
"From" : "+18319999999", //twilio account number
"Parameters" : "{\"opportunityId\":\"\(opportunityId)\",\"surveyType\":\"\(surveyType)\"}"
]
let urlString = "https://studio.twilio.com/v1/Flows/FW98f493a6cd8c930ede81fd31f16f62e3/Executions"
Alamofire.request(urlString, method: .post, parameters: data, encoding: URLEncoding.default, headers: nil)
.authenticate(user: "ACCOUNTID-FROM-CONSOLE", password: "ITS-A-SECRET")
.responseJSON {
response in
switch response.result {
case .success:
print(response)
completion("success" as AnyObject, nil)
break
case .failure(let error):
self.lastError = error
print(error)
completion(nil, .FailedRequest)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment