Created
March 16, 2019 16:36
-
-
Save quintonwall/3daf22817e548a0e6e152ece962400f5 to your computer and use it in GitHub Desktop.
Call Twilio Survey From Swift
This file contains 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
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