-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
54 lines (46 loc) · 1.13 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import dotenv from 'dotenv';
dotenv.config();
import createQueue from './queue.js';
import {
sendChatAction,
sendMessage,
launchBot,
handleStart,
handleCommand,
handleMessage,
} from './service.js';
const queue = createQueue();
queue.on('failed', (job, err) => {
console.log(`Job ${job.id} failed with error ${err.message}`);
});
queue.on('completed', (job, result) => {
console.log(`Job ${job.id} completed with result:`, result);
});
handleStart((ctx) => ctx.reply('Welcome to Telegraf starter bot\n\nsay /wassup'));
handleCommand(['wassup', 'sup'], async (ctx) => {
try {
await sendChatAction(ctx.chat.id, 'typing'); // disable for topics as this shows on main chat
queue.add(
{ chatId: ctx.chat.id, messageId: ctx.message.message_id },
{
attempts: 5,
backoff: {
type: 'fixed',
delay: 2000,
},
}
);
} catch (error) {
console.error('Error adding job to queue:', error);
}
});
handleMessage(async (ctx) => {
await sendMessage(
ctx.chat.id,
'You talking to me? Remove on message to only get replies to commands',
{
reply_to_message_id: ctx.message.message_id,
}
);
});
launchBot();