Telegraf: send message to channel every min

Created on 16 Mar 2019  路  3Comments  路  Source: telegraf/telegraf

its not work
TypeError: Cannot read property 'telegram' of undefined
can y help me

cron.schedule('* * * * *', (ctx) => {
   console.log('in time schudle');

   ctx.telegram.sendMessage('@mychannel','send this every min' ).then((result) => {

   }).catch((err) => {

   });


    })

Most helpful comment

  1. ctx doesn't contain sendMessage() method
  2. ctx is not declared there. You can use ctx only in handlers like
bot.hear('hi', (ctx) => {
  // here ctx is defined
)}

But:

setInterval(function () {
  // here is no ctx
)}

So as said @TiagoDanin use bot.telegram.sendMessage(id, text, extra)

All 3 comments

Use bot.telegram.sendMessage(...)

  1. ctx doesn't contain sendMessage() method
  2. ctx is not declared there. You can use ctx only in handlers like
bot.hear('hi', (ctx) => {
  // here ctx is defined
)}

But:

setInterval(function () {
  // here is no ctx
)}

So as said @TiagoDanin use bot.telegram.sendMessage(id, text, extra)

@rozi98 context only available on update, you can use bot.telegram.sendMessage instead.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bostrot picture bostrot  路  3Comments

Chibears85 picture Chibears85  路  3Comments

kuhel picture kuhel  路  3Comments

bostrot picture bostrot  路  3Comments

agstover picture agstover  路  3Comments