Skip to content

Instantly share code, notes, and snippets.

@renatoliveira
Created July 16, 2017 19:27
Show Gist options
  • Save renatoliveira/053dd1cab4192fea72dd160ccba02116 to your computer and use it in GitHub Desktop.
Save renatoliveira/053dd1cab4192fea72dd160ccba02116 to your computer and use it in GitHub Desktop.
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