Created
July 16, 2017 19:27
-
-
Save renatoliveira/053dd1cab4192fea72dd160ccba02116 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
global class Telegram { | |
public static void sendMessage (String message, User user) { | |
sendMessage(message, user.TelegramId__c); | |
} | |
public static void sendMessage (String message, String telegram_id) { | |
HttpRequest req = new HttpRequest(); | |
req.setEndpoint('https://api.telegram.org/bot' + TelegramBot__c.getOrgDefaults().Token__c + '/sendMessage'); | |
req.setMethod('POST'); | |
req.setHeader('content-type', 'application/json'); | |
req.setBody('{"chat_id" : "' + telegram_id + '", "text" : "' + message + '"}'); | |
Http http = new Http(); | |
HttpResponse res = http.send(req); | |
System.debug(res.getBody()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment