我成功集成了电报机器人,但我想将 Bot 添加到频道中并使这个脚本在那里工作,我尝试将 Chat_Id 更改为我的频道聊天 ID,但没有任何效果。
有人知道如何在我的频道上使用此功能吗?
var token = "This is my TOKEN";
var SheetID = "This is my Sheet ID";
function doPost(e) {
var stringJson = e.postData.getDataAsString();
var updates = JSON.parse(stringJson);
if(updates.message.text){
sendText(updates.message.chat.id,searchDataByCommand(updates.message.text));
}
}
function getRows(){
var rangeName = 'Tbot!A2:B';
var rows = Sheets.Spreadsheets.Values.get(SheetID, rangeName).values;
return rows;
}
function searchDataByCommand(idcommand){
var datacommand = getRows();
for (var row = 0; row < datacommand.length; row++) {
if(datacommand[row][0]==idcommand){
return datacommand[row][1];
}
}
return "";
}
function testgetrow(){
var nama = searchDataByCommand(Saldo);
var x = "";
}
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);
}