I'm trying to make a bot using google apps script for my telegram group to record scam contracts to google sheets. I can't get the /scam 0xtest00000000 to make the bot respond, or record it to my google sheets. I can do it with /^@/ and it works fine, but I want to use common style tg bot commands. I've tried putting in text = "", I've tried slicing, I've tried all sorts of things. Any help would be appreciated.
function getMe() {
var response = UrlFetchApp.fetch(url + "/getMe");
Logger.log(response.getContentText());
}
function setWebhook() {
var response = UrlFetchApp.fetch(url + "/setWebhook?url=" +
webAppUrl);
Logger.log(response.getContentText());
}
function sendText(chat_id, text) {
let data = {
method: "post",
payload: {
method: "sendMessage",
chat_id: String(chat_id),
text: text,
parse_mode: "HTML"
}
};
UrlFetchApp.fetch(url + "/sendMessage?chat_id=" + chat_id + "$texts"
+ encodeURIComponent(text));
}
function doGet(e) {
return HtmlService.createHtmlOutput ("Hello" + JSON.stringify(e));
}
function doPost(e) {
try {
let contents = JSON.parse(e.postData.contents);
GmailApp.sendEmail(Session.getEffectiveUser().getEmail(), "Telegram
Bot Update",JSON.stringify(contents,null,4));
let text = contents.message.text;
let chat_id = contents.message.chat.id;
let name = contents.message.from.first_name + " " +
contents.message.from.last_name;
let user_id = contents.message.from.id;
let username = contents.message.from.username;
let contract = text.slice(1).split(" ")[0];
// let item = text.split(" ");
let scam = "/scam";
// let com1 = scam.split(' ')[0];
if(text == scam)) {
SpreadsheetApp.openById(ssid).appendRow([new
Date(),user_id,username,name,contract]);
sendText(chat_id, "Contract address " + contract + " has been added
to the list." );
}
} catch(e) {
sendText(lbsId,"Error" + JSON.stringify(e,null,4));
}
}