|
function onOpen() { |
|
var ui = SlidesApp.getUi(); |
|
ui.createMenu('GDG Tools') |
|
.addSubMenu(ui.createMenu('Share this slide on "GDG Italia"') |
|
.addItem('Telegram (favorite)', 'shareItalyTelegram') |
|
.addItem('Slack', 'shareItalySlack')) |
|
.addSubMenu(ui.createMenu('Share this slide on "GDG Spain"') |
|
.addItem('Telegram', 'shareSpainTelegram') |
|
.addItem('Slack (favorite)', 'shareSpainSlack')) |
|
.addToUi(); |
|
} |
|
|
|
|
|
// Menu functions |
|
|
|
function shareItalyTelegram() { |
|
var slideInfo = getCurrentSlide(); |
|
var properties = PropertiesService.getScriptProperties(); |
|
var tToken = properties.getProperty('ITALY_TELEGRAM_TOKEN'); |
|
var chatId = properties.getProperty('ITALY_TELEGRAM_CHAT_ID'); |
|
sendTelegramPhoto(tToken, chatId, slideInfo['thumbnail'], slideInfo['url']); |
|
} |
|
|
|
function shareItalySlack() { |
|
var slideInfo = getCurrentSlide(); |
|
var properties = PropertiesService.getScriptProperties(); |
|
var webhook = properties.getProperty('ITALY_SLACK_WEBHOOK'); |
|
var channel = properties.getProperty('ITALY_SLACK_CHANNEL'); |
|
sendSlackPhoto(webhook, channel, slideInfo['thumbnail'], slideInfo['url']); |
|
} |
|
|
|
function shareSpainTelegram() { |
|
var slideInfo = getCurrentSlide(); |
|
var properties = PropertiesService.getScriptProperties(); |
|
var tToken = properties.getProperty('SPAIN_TELEGRAM_TOKEN'); |
|
var chatId = properties.getProperty('SPAIN_TELEGRAM_CHAT_ID'); |
|
sendTelegramPhoto(tToken, chatId, slideInfo['thumbnail'], slideInfo['url']); |
|
} |
|
|
|
function shareSpainSlack() { |
|
var slideInfo = getCurrentSlide(); |
|
var properties = PropertiesService.getScriptProperties(); |
|
var webhook = properties.getProperty('SPAIN_SLACK_WEBHOOK'); |
|
var channel = properties.getProperty('SPAIN_SLACK_CHANNEL'); |
|
sendSlackPhoto(webhook, channel, slideInfo['thumbnail'], slideInfo['url']); |
|
} |
|
|
|
|
|
// Utility |
|
|
|
function getCurrentSlide() { |
|
var presentation = SlidesApp.getActivePresentation(); |
|
var presentationId = presentation.getId(); |
|
var pageId = presentation.getSelection().getCurrentPage().getObjectId(); |
|
return { |
|
'url': presentation.getUrl() + '#slide=id.' + pageId, |
|
'thumbnail': Slides.Presentations.Pages.getThumbnail(presentationId, pageId).contentUrl |
|
} |
|
} |
|
|
|
function sendTelegramPhoto(telegramToken, chatId, imageUrl, caption) { |
|
return UrlFetchApp.fetch('https://api.telegram.org/bot' + telegramToken + '/sendPhoto', { |
|
'method' : 'post', |
|
'contentType': 'application/json', |
|
'payload' : JSON.stringify({ |
|
'chat_id': chatId, |
|
'photo': imageUrl, |
|
'caption': caption |
|
}) |
|
}); |
|
} |
|
|
|
function sendSlackPhoto(webhook, channel, imageUrl, caption) { |
|
return UrlFetchApp.fetch(webhook, { |
|
'method': 'post', |
|
'contentType': 'application/json', |
|
'payload': JSON.stringify({ |
|
'channel': channel, |
|
'text': caption, |
|
'attachments': [{ |
|
'fallback': 'Slide', |
|
'image_url': imageUrl |
|
}] |
|
}) |
|
}); |
|
} |
|
|
|
// by Jackl - Omar Miatello |