Skip to content

Instantly share code, notes, and snippets.

@luchaninov
Created April 19, 2018 22:52
Show Gist options
  • Save luchaninov/d0795cd223ffae3cb7474fdadb2a2fce to your computer and use it in GitHub Desktop.
Save luchaninov/d0795cd223ffae3cb7474fdadb2a2fce to your computer and use it in GitHub Desktop.
TelegramBot: Bitcoin price from Google Sheets
function spamTelegram() {
var telegramToken = 'bot111111111:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA-v4'; // change to your token
var telegramChat = '-1111111111111'; // change to your chat id or to public "@channelname"
var url,response,data,msg;
url = 'https://api.coindesk.com/v1/bpi/currentprice/usd.json?showex=1&calc=1';
response = UrlFetchApp.fetch(url, {'muteHttpExceptions': true});
data = JSON.parse(response.getContentText());
msg = 'BTC = $' + data.bpi.USD.rate.replace(/\.\d+/, '');
url = 'https://api.telegram.org/' +
telegramToken + '/sendMessage?chat_id=' + telegramChat + '&text=' + encodeURIComponent(msg);
response = UrlFetchApp.fetch(url, {'muteHttpExceptions': true});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment