Classes

State

Conversation state storage

ChatLog

Chat logs storage

Functions

createProcessor(reducer, processorOptions, [stateStorage])

Create a chat event processor

createRouter(reducer, verifyToken, [log])

Create an express route for accepting messenger events

 

State

Conversation state storage

Kind: global class

 

state.connectAndSubscribe(senderId, [defaultState], [timeout]) ⇒ Promise.<Object>

Load state and lock for other requests

Kind: instance method of State

Param Type Default Description
senderId * user identifier
[defaultState] Object Object given default state
[timeout] number 300 given default state
 

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

Called after load for postprocessing purposes

Kind: instance method of State

Param Type Description
req Request chat request
state Object given default state
 

state.saveState(state) ⇒ Promise

Called for saving state

Kind: instance method of State

Param Type Description
state Object given default state
 

ChatLog

Chat logs storage

Kind: global class

 

chatLog.log(userId, responses, request)

Log single event

Kind: instance method of ChatLog

Param Type Description
userId string
responses Array.<Object> list of sent responses
request Object event request
 

chatLog.error(err, userId, [responses], [request])

Log single event

Kind: instance method of ChatLog

Param Type Description
err any error
userId string
[responses] Array.<Object> list of sent responses
[request] Object event request
 

createProcessor(reducer, processorOptions, [stateStorage])

Create a chat event processor

Kind: global function

Param Type Description
reducer function \ Router Root router object or processor function
processorOptions Object settings for message processing
[processorOptions.pageToken] string page token
[processorOptions.appSecret] string bot application secret
[processorOptions.appUrl] string where the bot application is deployed
[processorOptions.timeout] number how long the state will be locked for single event
[processorOptions.log] Object console.log/error/warn like object
[processorOptions.defaultState] Object default conversation state
[processorOptions.chatLog] MongoChatLog discussion logger
[processorOptions.tokenStorage] MongoBotToken storage for chabot tokens
[processorOptions.senderFnFactory] function override default sender function
[processorOptions.securityMiddleware] function override webview calls authorizer
[processorOptions.cookieName] string webview cookie (for default securityMiddleware)
[processorOptions.loadUsers] boolean set false to not load user profiles
[processorOptions.userLoader] Object override default user loader
[processorOptions.onSenderError] function override default sender error reporter
[processorOptions.autoTyping] Object \ boolean enable auto typing
[processorOptions.autoTyping.time] number default typing time
[processorOptions.autoTyping.perCharacters] number typing time per character
[processorOptions.autoTyping.minTime] number auto typing lower threshold
[processorOptions.autoTyping.maxTime] number auto typing upper threshold
[stateStorage] MongoState storage for states

Example

const express = require('express');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const { createRouter, createProcessor } = require('botnaut/express');

const handler = (req, res, postBack) => {
    res.typingOn()
        .wait();

    switch (req.action()) {
        case 'hello':
            res.text('Hello world');
            return;
        default:
            // send one quick reply
            res.text('What you want?', {
                hello: 'Say hello world'
            })
    }
};

const processor = createProcessor(handler, {
    pageToken: 'stringhere',
    appSecret: 'botappsecret'
});

app = express();

app.use('/bot', createRouter(processor));

mongoose.connect('mongodb://localhost/myapp')
    .then(() => app.listen(3000));
 

createRouter(reducer, verifyToken, [log])

Create an express route for accepting messenger events

Kind: global function

Param Type Description
reducer function \ Router Root router object or processor function
verifyToken string chatbot application token
[log] Object console.* like logger object

results matching ""

    No results matching ""