Classes

GraphApi

Experimental chatbot API

Functions

postBackApi(processor, [acl])PostBackAPI

Create a postback API

validate(bot, validationRequestBody, postBackTest, textTest)
validateBotApi(botFactory, [postBackTest], [textTest], [acl])ValidateBotAPI

Test the bot configuration

conversationsApi(stateStorage, chatLogStorage, notifications, [acl], options)ConversationsAPI

Create a conversations API for retrieving conversations and it's history

apiAuthorizer(args, ctx, acl)boolean

If API call is authorized - use for own implementations of API endpoints

Typedefs

GraphQlResponse : object
PostBackAPI : object
ValidateBotAPI : object
conversation : object
StateStorage : object
Notifications : object
ChatLogStorage : object
textFilterany

Function for filtration of string output

 

GraphApi

Experimental chatbot API

Kind: global class

 

new GraphApi(apis, options)

Param Type Description
apis Array.<object> list of connected APIs
options object API options
options.token string \ Promise.<string> wingbot token
[options.appToken] string public token
[options.groups] Array.<string> list of allowed bot groups
[options.useBundledGql] boolean uses library bundled graphql definition
 

graphApi.request(body, headers, [wingbotToken]) ⇒ Promise.<GraphQlResponse>

Kind: instance method of GraphApi

Param Type
body object
body.query object
[body.variables] object
[body.operationName] string
headers object
[headers.Authorization] string
[headers.authorization] string
[wingbotToken] string
 

postBackApi(processor, [acl]) ⇒ PostBackAPI

Create a postback API

Kind: global function

Param Type Description
processor Object running messaging channel, like Facebook
[acl] Array.<string> \ function limit api to array of groups or use auth function

Example

const { GraphApi, postBackApi } = require('wingbot');

const api = new GraphApi([
    postBackApi(channel)
], {
    appToken: 'API-will-be-accessible-with-this-token-in-Authorization-header'
})
 

validate(bot, validationRequestBody, postBackTest, textTest)

Kind: global function

Param Type Default
bot object
validationRequestBody object
postBackTest string \ function null
textTest string \ function null
 

validateBotApi(botFactory, [postBackTest], [textTest], [acl]) ⇒ ValidateBotAPI

Test the bot configuration

Kind: global function

Param Type Default Description
botFactory function function, which returns a bot
[postBackTest] string \ function \ null null postback action to test
[textTest] string \ function \ null null random text to test
[acl] Array.<string> \ function limit api to array of groups or use auth function

Example

const { GraphApi, validateBotApi, Tester } = require('wingbot');

const api = new GraphApi([
    validateBotApi(botFactory, 'start', 'hello')
], {
    token: 'wingbot-token'
})

// OR WITH FUNCTION

const api = new GraphApi([
    validateBotApi(botFactory, async (t, bot) => {
        const tester = new Tester(bot);

        tester.postBack('start');
    })
], {
    token: 'wingbot-token'
})
 

conversationsApi(stateStorage, chatLogStorage, notifications, [acl], options) ⇒ ConversationsAPI

Create a conversations API for retrieving conversations and it's history

Kind: global function

Param Type Default Description
stateStorage StateStorage
chatLogStorage ChatLogStorage
notifications Notifications
[acl] Array.<string> \ function limit api to array of groups or use auth function
options object
[options.stateTextFilter] textFilter optional funcion for filtering data in states

Example

const { GraphApi, conversationsApi } = require('wingbot');
const BOT_UPDATE_GROUPS = ['botEditor', 'botAdmin', 'botUser'];

function stateTextFilter (value, key) {
    if (key === 'credentials.password') {
        return '****';
    }
    return value;
}

const api = new GraphApi([
    conversationsApi(
        stateStorage, chatLogStorage, notifications, BOT_UPDATE_GROUPS,
        { stateTextFilter }
    )
], {
    token: 'my-secret-token'
});
 

apiAuthorizer(args, ctx, acl) ⇒ boolean

If API call is authorized - use for own implementations of API endpoints

Kind: global function

Param Type Description
args object gql request
ctx Object request context
acl Array.<string> \ null \ function custom acl settings

Example

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

function createApi (acl = null) {
    return {
         gqlEndpoint (args, ctx) {
             if (!apiAuthorizer(args, ctx, acl)) {
                 return null;
             }
         }
    }
}
 

GraphQlResponse : object

Kind: global typedef

Param Type
[data] *
[errors] Array.<object>
 

PostBackAPI : object

Kind: global typedef
Properties

Name Type
postBack function
 

ValidateBotAPI : object

Kind: global typedef
Properties

Name Type
validateBot function
 

conversation : object

Kind: global typedef

 

StateStorage : object

Kind: global typedef
Properties

Name Type
getStates function
getState function
 

Notifications : object

Kind: global typedef
Properties

Name Type
getSubscribtions function
 

ChatLogStorage : object

Kind: global typedef
Properties

Name Type
getInteractions function
 

textFilter ⇒ any

Function for filtration of string output

Kind: global typedef

Param Type
value string
key string

results matching ""

    No results matching ""