Created
February 26, 2022 17:25
-
-
Save Lobbyra/65f5c742888856a3fe7900b73acca077 to your computer and use it in GitHub Desktop.
App Script (google) code for connect circleci with telegram channel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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