Naltox / telegram-node-bot

Node module for creating Telegram bots.
MIT License
720 stars 144 forks source link

Send message by shedule #168

Closed AndryFM closed 7 years ago

AndryFM commented 7 years ago

How i can send message without user request? I tried tg.$.sendMessage(chatId, 'text'); but its dosnt work, i dont see info about it in docs

Z3nto commented 7 years ago

You can only use $ if the user has requested. You need to use tg.api.sendMessage(chatId, 'Hi');

AndryFM commented 7 years ago

You need to use tg.api.sendMessage(chatId, 'Hi');

@Z3nto thanks for this way!

but i have one more question: when I write console.log(new Date()); in my app.js - I get 5 messages in console also I got 5 messages in chat - when i write tg.api.sendMessage(chatId, 'Hi'); maybeits because

Telegram Master started, 4 CPUs found, 4 workers will start

but what i can do with it?

AndryFM commented 7 years ago

I found solution: https://github.com/Naltox/telegram-node-bot#clustering

const tg = new Telegram.Telegram('YOUR_TOKEN', {
    workers: 1
})

tg.sendMessage(123, 'test message') //will be sent 2 times (one time on master and one time on worker)

tg.onMaster(() => {
    tg.sendMessage(123, 'test message') //will be sent one time
})

thanks for all ;)