Classes

MemoryStateStorage

Memory conversation state storage for testing purposes

Translate
Translate
ReturnSender

Functions

bufferloader(url, [limit], [limitJustByBody], [redirCount])Promise.<Buffer>

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

Typedefs

State : Object
StateCondition : Object
textFilterstring

Text filter function

 

MemoryStateStorage

Memory conversation state storage for testing purposes

Kind: global class

 

memoryStateStorage.getState(senderId, pageId) ⇒ Promise.<(State|null)>

Kind: instance method of MemoryStateStorage
Params

  • senderId string
  • pageId string
 

memoryStateStorage.getOrCreateAndLock(senderId, pageId, defaultState, lockTimeout) ⇒ Promise.<State>

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

  • senderId string - sender identifier
  • pageId string - page or channel identifier
  • defaultState Object - default state of the conversation
  • lockTimeout number = 300 - duration of lock
 

memoryStateStorage.saveState(state) ⇒ Promise

Kind: instance method of MemoryStateStorage
Params

  • state Object - conversation state
 

memoryStateStorage.getStates(condition, limit, lastKey) ⇒ Promise.<{Array.<data:State>, lastKey:string}>

Kind: instance method of MemoryStateStorage
Params

 

Translate

Kind: global class

 

new Translate()

Tool for text translation

 

new Translate([options])

Params

  • [options] Object
    • [.sourcePath] string - optional source path of translation folder
    • [.fileSuffix] string - by default .locale.po
 

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

Creates static translator for static settings

Kind: instance method of Translate
Params

  • languages Array.<string> - list of required languages

Example

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

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
Params

  • languageResolver function

Example

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

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])

Params

  • [options] Object
    • [.sourcePath] string - optional source path of translation folder
    • [.fileSuffix] string - by default .locale.po
 

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

Creates static translator for static settings

Kind: instance method of Translate
Params

  • languages Array.<string> - list of required languages

Example

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

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
Params

  • languageResolver function

Example

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

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

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

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

ReturnSender

Kind: global class

 

new ReturnSender(options, userId, incommingMessage, logger)

Params

  • options Object
    • [.textFilter] textFilter - filter for saving the texts
  • userId string
  • incommingMessage Object
  • logger console - console like logger
 

returnSender.textFilter : textFilter

Preprocess text for NLP For example to remove any confidential data

Kind: instance property of ReturnSender
Params

  • text string
 

returnSender.modifyStateAfterLoad() ⇒ Promise.<(Object|null)>

Kind: instance method of ReturnSender

 

returnSender.modifyStateBeforeStore() ⇒ Promise.<(Object|null)>

Kind: instance method of ReturnSender

 

bufferloader(url, [limit], [limitJustByBody], [redirCount]) ⇒ Promise.<Buffer>

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

Kind: global function
Params

  • 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 }))
    }
});
 

State : Object

Kind: global typedef
Properties

Name Type
senderId string
pageId string
state Object
 

StateCondition : Object

Kind: global typedef
Properties

Name Type
[search] string
 

textFilter ⇒ string

Text filter function

Kind: global typedef
Returns: string - - filtered text
Params

  • text string - input text

results matching ""

    No results matching ""