Classes

MemoryStateStorage

Memory conversation state storage for testing purposes

Translate
Translate

Functions

bufferloader(url, [limit], [limitJustByBody], [redirCount])

Downloads a file from url into a buffer. Supports size limits and redirects.

 

MemoryStateStorage

Memory conversation state storage for testing purposes

Kind: global class

 

memoryStateStorage.getOrCreateAndLock(senderId, defaultState) ⇒ Promise.<Object>

Kind: instance method of MemoryStateStorage
Returns: Promise.<Object> - - conversation state

Param Type Description
senderId any sender identifier
defaultState Object default state of the conversation
 

memoryStateStorage.onAfterStateLoad(req, state) ⇒ Promise.<Object>

Kind: instance method of MemoryStateStorage
Returns: Promise.<Object> - - conversation state

Param Type Description
req Request chat request
state Object conversation state
 

memoryStateStorage.saveState(state) ⇒ Promise

Kind: instance method of MemoryStateStorage

Param Type Description
state Object conversation state
 

Translate

Kind: global class

 

new Translate()

Tool for text translation

 

new Translate([options])

Param Type Description
[options] object
[options.sourcePath] string optional source path of translation folder
[options.fileSuffix] string by default .locale.po
 

translate.translator(languages) ⇒ Promise.<object>

Creates static translator for static settings

Kind: instance method of Translate

Param Type Description
languages Array.<string> list of required languages

Example

const { Translate } = require('botnaut');

const translate = new Translate({ sourcePath: __dirname });

const t = translate.translator(['cs', 'en']);

// czech
t.cs.t('requested text');

// english
t.en.t('requested text');
 

translate.middleware(languageResolver) ⇒ function

Bots middleware for text translations

  • will be looking for <lang>.locale.po by default

Kind: instance method of Translate

Param Type
languageResolver function

Example

const { Translate } = require('botnaut');

const translate = new Translate({ sourcePath: __dirname });

bot.use(translate.middleware((req, res) => 'cs'));

bot.use((req, res) => {
   res.text(res.t('Translated text'));
});
 

Translate

Kind: global class

 

new Translate()

Tool for text translation

 

new Translate([options])

Param Type Description
[options] object
[options.sourcePath] string optional source path of translation folder
[options.fileSuffix] string by default .locale.po
 

translate.translator(languages) ⇒ Promise.<object>

Creates static translator for static settings

Kind: instance method of Translate

Param Type Description
languages Array.<string> list of required languages

Example

const { Translate } = require('botnaut');

const translate = new Translate({ sourcePath: __dirname });

const t = translate.translator(['cs', 'en']);

// czech
t.cs.t('requested text');

// english
t.en.t('requested text');
 

translate.middleware(languageResolver) ⇒ function

Bots middleware for text translations

  • will be looking for <lang>.locale.po by default

Kind: instance method of Translate

Param Type
languageResolver function

Example

const { Translate } = require('botnaut');

const translate = new Translate({ sourcePath: __dirname });

bot.use(translate.middleware((req, res) => 'cs'));

bot.use((req, res) => {
   res.text(res.t('Translated text'));
});
 

bufferloader(url, [limit], [limitJustByBody], [redirCount]) ⇒

Downloads a file from url into a buffer. Supports size limits and redirects.

Kind: global function
Returns: Promise.

Param Type Default Description
url string
[limit] number 0 limit in bytes
[limitJustByBody] boolean false when true, content size in header is ignored
[redirCount] number 3 maximmum amount of redirects

Example

router.use('*', (req, res, postBack) => {
    if (req.isFile()) {
        bufferloader(req.attachmentUrl())
            .then(buffer => postBack('downloaded', { data: buffer }))
            .catch(err => postBack('donwloaded', { err }))
    }
});

results matching ""

    No results matching ""