Skip to content

Instantly share code, notes, and snippets.

@Lobbyra
Created February 26, 2022 17:25
Show Gist options
  • Save Lobbyra/65f5c742888856a3fe7900b73acca077 to your computer and use it in GitHub Desktop.
Save Lobbyra/65f5c742888856a3fe7900b73acca077 to your computer and use it in GitHub Desktop.
App Script (google) code for connect circleci with telegram channel
var token = "YOUR TELEGRAM API CODE";
var telegramUrl = "https://api.telegram.org/bot" + token;
var webAppUrl = "THE URL OF THE APP SCRIPT INSTANCE"
function setWebhook() {
var url = telegramUrl + "/setWebhook?url=" + webAppUrl;
var response = UrlFetchApp.fetch(url);
}
function sendMessage(chat_id, text) {
var url = telegramUrl + "/sendMessage?chat_id=" + chat_id + "&text="+ text;
var response = UrlFetchApp.fetch(url);
Logger.log(response.getContentText());
}
function doPost(e) {
var contents = JSON.parse(e.postData.contents);
if (!contents.type || contents.type == "ping") {
return;
}
var msg = `🚀 CIRCLECI 🚀 : ${contents.project.name} : `;
if (contents.type == "job-completed") {
msg += `${contents.job.name} job : `;
if (contents.job.status == "success") {
msg += "✅";
} else {
msg += "❌";
}
} else if (contents.type == "workflow-completed") {
msg += `${contents.workflow.name} workflow : `;
if (contents.workflow.status == "success") {
msg += "✅";
} else {
msg += "❌";
}
}
var chat_id = contents.webhook.name.split(" - ")[1];
sendMessage(chat_id, msg);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment