File: get-updates.js

package info (click to toggle)
node-telegram-bot-api 2.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 2,964 kB
  • sloc: javascript: 1,333; makefile: 2
file content (46 lines) | stat: -rw-r--r-- 1,131 bytes parent folder | download
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
const TG = require('../lib/index')
const fs = require('fs')
const path = require('path')

const BOT_TOKEN = process.env.BOT_TOKEN
if (!BOT_TOKEN) {
    console.log('Opps, you need to define your BOT_TOKEN')
}

const api = new TG({
    token: BOT_TOKEN
})

api.setMessageProvider(new TG.GetUpdateMessageProvider())
api.start()
.then(() => {
    console.log('API is started')
})
.catch(console.err)

api.on('update', (update) => {
    const chat_id = update.message.chat.id

    // Send text message
    api.sendMessage({
        chat_id: chat_id,
        text: 'I got following message from you: *'+ update.message.text +'*',
        parse_mode: 'Markdown',
        reply_markup: {
            inline_keyboard: [
                [
                    {
                        text: 'Visit us!',
                        url: 'https://github.com/mast/telegram-bot-api'}
                ]
            ]
        }
    })

    // Send celebi
    api.sendAnimation({
        chat_id: chat_id,
        caption: 'Shiny celebi appeared..',
        animation: fs.createReadStream(path.join(__dirname, '../test/assets/celebi.gif'))
    })
})