Skip to content

Instantly share code, notes, and snippets.

@st-small
Created November 1, 2018 13:52
Show Gist options
  • Save st-small/26f5abf7da80bb96d9f5c85969cdf5ba to your computer and use it in GitHub Desktop.
Save st-small/26f5abf7da80bb96d9f5c85969cdf5ba to your computer and use it in GitHub Desktop.
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