repl.it
@functorflow/

myws-tg-bot

Nodejs

No description

fork
loading
Files
  • index.js
  • locales
  • Packager files
  • package-lock.json
  • package.json
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
55
const Telegraf = require('telegraf')
const TelegrafI18n = require('telegraf-i18n')
const path = require('path')
const { Extra } = Telegraf

__dirname = path.resolve();

// i18n options
const i18n = new TelegrafI18n({
  directory: path.resolve(__dirname, 'locales'),
  defaultLanguage: 'en',
  sessionName: 'session',
  useSession: true,
  templateData: {
    pluralize: TelegrafI18n.pluralize,
    uppercase: (value) => value.toUpperCase()
  }
})


const bot = new Telegraf(process.env.BOT_TOKEN)
bot.use(Telegraf.session())
bot.use(i18n.middleware())

// Start message handler
bot.start(({ i18n, replyWithHTML }) => replyWithHTML(i18n.t('greeting')))

// Using i18n helpers
bot.command('help', TelegrafI18n.reply('greeting', Extra.HTML()))

// Set locale to `en`
bot.command('en', ({ i18n, replyWithHTML }) => {
  i18n.locale('en-US')
  return replyWithHTML(i18n.t('greeting'))
})

// Set locale to `ru`
bot.command('ru', ({ i18n, replyWithHTML }) => {
  i18n.locale('ru')
  return replyWithHTML(i18n.t('greeting'))
})


bot.command('invoice', ({ session, i18n, replyWithDocument }) => {

  return replyWithDocument({
    url: 'https://invoice-ws.functorflow.repl.co/',
    filename: 'invoice.pdf'
  })

})


bot.startPolling()
?