26 lines
1007 B
JavaScript
26 lines
1007 B
JavaScript
function doPost(e) {
|
|
const contents = JSON.parse(e.postData.contents);
|
|
if (contents.message?.media_group_id || !contents.message?.text) {
|
|
return;
|
|
}
|
|
|
|
const found = contents.message.text.match(/https?:\/\/(?:mobile\.)?twitter\.com\/(\w+)\/status\/(\d+)(\/photo\/\d)?/);
|
|
if (found) {
|
|
// Feel free to hardcode bot token, reducing PropertiesService usage quota
|
|
UrlFetchApp.fetch(`https://api.telegram.org/bot${PropertiesService.getScriptProperties().getProperty('TELEGRAM_BOT_TOKEN')}/`, {
|
|
method: "post",
|
|
payload: {
|
|
method: "sendMessage",
|
|
chat_id: String(contents.message.chat.id),
|
|
text: `https://fxtwitter.com/${found[1]}/status/${found[2]}${found[3] || ''}`,
|
|
reply_to_message_id: String(contents.message.message_id),
|
|
disable_notification: true,
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
function doGet() {
|
|
return HtmlService.createHtmlOutput('Webhook Endpoint for <a href="https://t.me/TangMo_fxtwitter_bot">@TangMo_fxtwitter_bot</a> Telegram bot');
|
|
}
|