-
-
Save cardoso/445cb692d8662cb7a209ca5a99410b51 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 botReply(channelType: String, channelId: String, botId: String, completion: @escaping () -> Void) { | |
let apiKey = "[insert_your_api_key_here]" | |
let jwt = "[insert_your_jwt_here]" | |
let response = [ | |
"I am a bot", | |
"Beep boop", | |
"Having trouble?", | |
"I can help" | |
].randomElement() ?? "" | |
let url = URL(string: "https://chat-us-east-1.stream-io-api.com/channels/\(channelType)/\(channelId)/message?api_key=\(apiKey)")! | |
var request = URLRequest(url: url) | |
request.allHTTPHeaderFields = ["Authorization": jwt, "stream-auth-type": "jwt"] | |
request.httpMethod = "POST" | |
request.httpBody = | |
""" | |
{ | |
"message" : { | |
"text" : "\(response)", | |
"silent" : false, | |
"user_id": "\(botId)" | |
} | |
} | |
""".data(using: .utf8) | |
let task = URLSession.shared.dataTask(with: request) { _,_,_ in | |
completion() | |
} | |
task.resume() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment