-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathbotCommand.js
More file actions
47 lines (41 loc) · 1.44 KB
/
Copy pathbotCommand.js
File metadata and controls
47 lines (41 loc) · 1.44 KB
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
const { Client, Structs } = require('tglib')
void async function() {
const client = new Client({
apiId: 'YOUR_API_ID',
apiHash: 'YOUR_API_HASH',
})
// Save tglib default handler which prompt input at console
const defaultHandler = client.callbacks['td:getInput']
// Register own callback for returning auth details
client.registerCallback('td:getInput', async (args) => {
if (args.string === 'tglib.input.AuthorizationType') {
return 'bot'
} else if (args.string === 'tglib.input.AuthorizationValue') {
return 'YOUR_BOT_TOKEN'
}
return await defaultHandler(args)
})
await client.ready
const { id: myId } = await client.fetch({ '@type': 'getMe' })
client.registerCallback('td:update', async (update) => {
if (update['@type'] === 'updateNewMessage') {
// check if message is sent from self
const sender = update['message']['sender_user_id']
if (sender !== myId) {
const { text: { text } } = update['message']['content']
let replyText
if (text.startsWith('/')) {
replyText = `Are you requested <b>${text}</b>?`
} else {
replyText = `Sorry I do not understand <b>${text}</b>.`
}
await client.tg.sendTextMessage({
'$text': new Structs.TextStruct(replyText, 'textParseModeHTML'),
'chat_id': 123456789,
'disable_notification': true,
'clear_draft': false,
})
}
}
})
}()