Created
November 1, 2018 13:52
-
-
Save st-small/26f5abf7da80bb96d9f5c85969cdf5ba to your computer and use it in GitHub Desktop.
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 sendToSlack() { | |
let slackUrl = "" | |
guard let url = URL(string: slackUrl) else { | |
print("Error: cannot create URL") | |
return | |
} | |
guard let position = lastPosition else { | |
print("Error: cannot get last position") | |
return | |
} | |
var urlRequest = URLRequest(url: url) | |
urlRequest.httpMethod = "POST" | |
let parameters: [String: Any] = ["channel": "", | |
"username": "Home Office Bot", | |
"text":"Hey there!] | |
let jsonParameters: Data | |
do { | |
jsonParameters = try JSONSerialization.data(withJSONObject: parameters, options: []) | |
urlRequest.httpBody = jsonParameters | |
} catch { | |
print("Error: cannot create JSON from todo") | |
return | |
} | |
let session = URLSession.shared | |
let task = session.dataTask(with: urlRequest) { | |
(data, response, error) in | |
guard error == nil else { | |
print(error!) | |
return | |
} | |
} | |
task.resume() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment