Created
September 14, 2018 17:58
-
-
Save nderkach/4a2a4461271ed01d6d3c90a8ed08209d 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
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