Closed bonkboykz closed 4 years ago
Thank you for reminding me this. I'll update the readme soon.
For now, you may look for how to use Typescript in your project.
Then enabling experimentalDecorators.
Then learn about the environment files.
Then have one environment variable BOT_TOKEN.
Then just create one instance of the class and start()
the bot.
Again, I'll add how to get started from the beginning in README file and then close this issue. You would know then more about this.
@bonkboykz
Yup, I configured tsconfig
, however I cannot launch the bot. So what I did, besides setting up BOT_TOKEN, was roughly this:
import { bot, command, IBot } from 'telegram-bot-framework';
interface SayHiBot extends IBot {};
@bot()
class SayHiBot {
@command()
async * sayHi() {
yield { message: 'Hello 👋' }
}
}
const bot = new SayHiBot();
if (bot.start) { // ts didn't like the fact, that start could be undefined
bot.start()
}
Yup, I configured
tsconfig
, however I cannot launch the bot. So what I did, besides setting up BOT_TOKEN, was roughly this:import { bot, command, IBot } from 'telegram-bot-framework'; interface SayHiBot extends IBot {}; @bot() class SayHiBot { @command() async * sayHi() { yield { message: 'Hello 👋' } } } const bot = new SayHiBot(); if (bot.start) { // ts didn't like the fact, that start could be undefined bot.start() }
It is because you may override the start function, you may have
bot.start!()
Structure is enough, just ensure you have set your bot token given by botfather in the environment variables and then ensure your node application is not terminated. Then, just send /sayHi to your bot.
Just a reminder that you should first get a token from telegram botfather.
Oh, I forgot the fact, that name of the command matches the pattern of /command
. Thank you, @incetarik !
Welcome @bonkboykz! You can rename it by passing a setting to decorator.
@command({ name: 'hi'})
async * sayHi() {
}
Now you can just /hi
I want to learn more about your thought after you use it!
Thanks for trying to simplify the process of building a bot on top of the telegraf!
Could you perhaps clarify the steps on how to get things going? I mean, starting from configuring typescript to use decorators to what parts are required to assemble and run
SayHiBot
.