incetarik / telegram-bot-framework

A bot framework for Telegram utilizing Telegraf library.
Mozilla Public License 2.0
10 stars 0 forks source link

Unclear instructions on how to get started #1

Closed bonkboykz closed 4 years ago

bonkboykz commented 4 years ago

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.

incetarik commented 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

bonkboykz commented 4 years ago

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()
}
incetarik commented 4 years ago

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.

bonkboykz commented 4 years ago

Oh, I forgot the fact, that name of the command matches the pattern of /command. Thank you, @incetarik !

incetarik commented 4 years ago

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!

incetarik commented 4 years ago

Setup information and one more example is added into ReadMe file.