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)

Params

  • apis Array.<object> - list of connected APIs
  • options object - API options
    • .token string | Promise.<string> - wingbot token
    • [.appToken] string - public token
    • [.groups] Array.<string> - list of allowed bot groups
 

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

Kind: instance method of GraphApi
Params

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

postBackApi(processor, [acl]) ⇒ PostBackAPI

Create a postback API

Kind: global function
Params

  • 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
Params

  • 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
Params

  • 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
Params

  • stateStorage StateStorage
  • chatLogStorage ChatLogStorage =
  • notifications Notifications =
  • [acl] Array.<string> | function = - limit api to array of groups or use auth function
  • options object
    • [.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
Params

  • 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
Params

  • [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
Params

  • value string
  • key string

results matching ""

    No results matching ""