import library 1Qn4F0nOiboBPZx0IWqBRBffD3ItfPFKgyH9VJwITj8arLhdyhd6uxXxC
to your project
Set up bot TOKEN
, WEBHOOK
url and HANDLERS
like this:
const TOKEN = '777777777:AABBBCCCDDDEEEFFFGGGHHHIII-1WCVKD8h',
WEBHOOK = 'https://script.google.com/macros/s/AKgdsfghbyU-XKv_mTgdsfgzKT_sdfgVCIvXbgiVbY4-WKZFrt_dghjLKNxlsadadsfBXLp/exec',
HANDLERS = [{
event: TBOT2.voice,
handler: (bot) => {
bot.apiRequest("sendMessage", {
text: "SHUT UP!",
chat_id: bot.update.message.chat.id,
reply_to_message_id: bot.update.message.message_id
})
}
}]
Handler is object containing 2 props: event (there "voice" event) and function that will triggerred via this event (
see full events list by editor autocomplete
)
Any non-predefined event will turned to bot
/command
, eg{event: 'hello'}
(handler just skipped there, bad idea) creates/hello
command
Handler function have only one argument: bot itself. If you need arguments of
/command arg1 arg2 etc
, take it frombot.args[]
Handler can be anonymous (like above) or not, example:
function blahblah(mybot) {
//do some stuff with mybot, SpreadSheet table, doc, all you want to do
}
HANDLERS = [{
event: 'video',
handler: blahblah
}]
Inside you handler you have access to important property update
and method apiRequest
apiRequest requires two args: method name and method params. Params is just {Object} containing telegram API parameters. It's easy like JSON, see first example above
Next, create function doPost:
function doPost(e) {
//e it's http postdata from telegram server
TBOT2.HANDLE(TOKEN, WEBHOOK, HANDLERS, e)
}
Next, deploy your app as public webapp (with anyone access and your name run), and copy link. This is your WEBHOOK
now.
Then, set up webhook, for example:
function sw() {
TBOT2.WEBHOOK(TOKEN, "your deployment url from prev step")
}
...and run it via Apps Script Editor integrated debugger.
Done! Do not forget, after code modification you must deploy your app again (it's more handy to "Manage deployments" -> "Edit" -> "New version", then you no need to update webhook url)