I created a telegram bot to fetch data from google sheet , now i want to add my bot to my private telegram channel
我创建了一个电报机器人来从Google Sheet获取数据,现在我想将我的机器人添加到我的私人电报频道
After addingy bot to the channel as a admin th bot dosnt reply on the channel
在将机器人作为管理员添加到频道后,不在频道上回复
So i want to send command ( on the channel ) and receive the reply from my bot ( on the channel too )
所以我想(在通道上)发送命令,并从我的机器人(也在通道上)接收回复
Here's my code
这是我的代码
var token = "";// ambil token dari BotFather telegram
var SheetID = "";// ambil ID pada URL Spreadsheets
var UrlPublish = ""; // ambil url hasil publish
var telegramUrl = "https://api.telegram.org/bot" + token;
function setWebhook() {
var url = telegramUrl + "/setWebhook?url=" + UrlPublish;
var response = UrlFetchApp.fetch(url);
}
function doPost(e) {
var stringJson = e.postData.getDataAsString();
var updates = JSON.parse(stringJson);
if(updates.message.text){
sendText(updates.message.chat.id,CariJadwalDariIDSheet(updates.message.text));
}
}
function AmbilSheet1(){
var rangeSheet = 'Sheet1!A2:C';
var rows = Sheets.Spreadsheets.Values.get(SheetID, rangeSheet).values;
return rows;
}
function CariJadwalDariIDSheet(IDjadwal){
var dataJadwal = AmbilSheet1();
for (var row = 0; row < dataJadwal.length; row++) {
if(dataJadwal[row][0]==IDjadwal){
return "Hari : " + dataJadwal[row][0] + "\n" +
"Jam belajar : " + dataJadwal[row][2] + "\n" +
"Mata Pelajaran : " + dataJadwal[row][1];
}
}
return "Jadwal tidak ditemukan." +"\n"+ "Silakan ketikkan hari lain.";
}
function sendText(chatid,text,replymarkup){
var data = {
method: "post",
payload: {
method: "sendMessage",
chat_id: String(chatid),
text: text,
parse_mode: "HTML",
reply_markup: JSON.stringify(replymarkup)
}
};
UrlFetchApp.fetch('https://api.telegram.org/bot' + token + '/', data);
}
I tried to add the bot to my private channel and send command but the bot didnt reply to me
我试图将机器人添加到我的私人频道并发送命令,但机器人没有回复我
更多回答
优秀答案推荐
我是一名优秀的程序员,十分优秀!