Skip to content

Instantly share code, notes, and snippets.

@nderkach
Created September 14, 2018 17:58
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 nderkach/4a2a4461271ed01d6d3c90a8ed08209d to your computer and use it in GitHub Desktop.
Save nderkach/4a2a4461271ed01d6d3c90a8ed08209d to your computer and use it in GitHub Desktop.
private func sendMessageToTelegram(withText text: String) {
// Send messages on telegram
let apiToken = "YOUR_TELEGRAM_TOKEN"
let chatId = "@YOUR_TELEGRAM_CHAT_NAME"
let strUrl = String(format: "https://api.telegram.org/bot%@/sendMessage?chat_id=%@&text=%@", apiToken, chatId, text.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)!)
Alamofire.request(strUrl).responseJSON { response in
if let json = response.result.value {
print("JSON: \(json)") // serialized json response
}
if let data = response.data, let utf8Text = String(data: data, encoding: .utf8) {
print("Data: \(utf8Text)") // original server data as UTF8 string
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment