Closed jakemake closed 1 year ago
this error coming from https://github.com/grammyjs/grammY
make sure u have 1 bot instance, instantiate it outside public async run()
, probably as singleton https://docs.adonisjs.com/guides/auth/custom-user-provider
feel free to share a github repo
this error coming from https://github.com/grammyjs/grammY
make sure u have 1 bot instance, instantiate it outside
public async run()
, probably as singleton https://docs.adonisjs.com/guides/auth/custom-user-providerfeel free to share a github repo
import type { ApplicationContract } from '@ioc:Adonis/Core/Application'
/* | -------------------------------------------------------------------------- | Provider |
---|---|---|
Your application is not ready when this file is loaded by the framework. | ||
Hence, the top level imports relying on the IoC container will not work. | ||
You must import them inside the life-cycle methods defined inside | ||
the provider class. | ||
@example: | ||
public async ready () { | ||
const Database = this.app.container.resolveBinding('Adonis/Lucid/Database') | ||
const Event = this.app.container.resolveBinding('Adonis/Core/Event') | ||
Event.on('db:query', Database.prettyPrint) | ||
} | ||
*/
Thanks for your reply, yeah i understand that it is grammy error and related to Adonisjs app lifecycle This issue hapenning only when i run scheduler command. I tried to move telegram bot initiating into new created Provider but even after, error continuing appear. I use polling method to get updates from TelegramBot Can you pls check this block of code?
import { Bot } from 'grammy'
export default class TelegramProvider {
constructor(protected app: ApplicationContract) {}
public register() {
this.app.container.singleton('Telegram/Bot', () => {
const config = this.app.config.get('telegram')
return new Bot(config.telegramConfig.botToken)
})
// Register your own bindings
}
public async boot() {
//start telegram bot
this.app.container.use('Telegram/Bot').stop()
}
public async ready() {
console.log('start bot')
// await this.app.container.use('Telegram/Bot').stop()
this.app.container.use('Telegram/Bot').start()
}
public async shutdown() {
console.log('stop bot')
this.app.container.use('Telegram/Bot').stop()
// Cleanup, since app is going down
}
}
@jakemake plz can u share/create a small repo with the bug?
@jakemake plz can u share/create a small repo with the bug?
https://github.com/jakemake/adonis-grammy-scheduler
i've created a new bot and included it to code
@jakemake you can only start one bot, you need to make sure only 1 instance is listening to messages
Note: I don't recommend starting the bot on a web instance
1- create new command GrammyListener
with loadApp/keepAlive + Start the bot => node ace grammy:listen
2- Other instances like web/console/queues/scheduler will use only the bot to query/execute stuff
ex: https://github.com/jakemake/adonis-grammy-scheduler/pull/1
@jakemake you can only start one bot, you need to make sure only 1 instance is listening to messages
Note: I don't recommend starting the bot on a web instance
1- create new command
GrammyListener
with loadApp/keepAlive + Start the bot =>node ace grammy:listen
2- Other instances like web/console/queues/scheduler will use only the bot to query/execute stuff
this is awesome, thanks! works perfectly
Every time when i start scheduler node ace scheduler:run i see errors (node:2572) UnhandledPromiseRejectionWarning: GrammyError: Call to 'getUpdates' failed! (409: Conflict: terminated by other getUpdates request; make sure that only one bot instance is running)