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
RequestParams : object
PostBackAPI : object
ValidateBotAPI : object
conversation : object
StateStorage : object
ChatLogStorage : object
TextFilterany

Function for filtration of string output

 

GraphApi

Experimental chatbot API

Kind: global class

 

new GraphApi(apis, options)

ParamTypeDescription
apisArray.<object>list of connected APIs
optionsobjectAPI options
options.tokenstring | Promise.<string>wingbot token
[options.appToken]stringpublic token
[options.groups]Array.<string>list of allowed bot groups
[options.useBundledGql]booleanuses library bundled graphql definition
[options.auditLog]AuditLog
 

graphApi.auditLog : AuditLog

Kind: instance property of GraphApi

 

graphApi._gql ⇒ GqlLib

Kind: instance property of GraphApi

 

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

Kind: instance method of GraphApi

ParamType
bodyobject
body.queryobject
[body.variables]object
[body.operationName]string
headersobject
[headers.Authorization]string
[headers.authorization]string
[headers.Origin]string
[headers.origin]string
[headers.Referer]string
[headers.referer]string
[wingbotToken]string
[params]RequestParams
 

postBackApi(processor, [acl]) ⇒ PostBackAPI

Create a postback API

Kind: global function

ParamTypeDescription
processorObjectrunning messaging channel, like Facebook
[acl]Array.<string> | functionlimit 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

ParamTypeDefault
botobject
validationRequestBodyobject
postBackTeststring | functionnull
textTeststring | functionnull
 

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

Test the bot configuration

Kind: global function

ParamTypeDefaultDescription
botFactoryfunctionfunction, which returns a bot
[postBackTest]string | function | nullnullpostback action to test
[textTest]string | function | nullnullrandom text to test
[acl]Array.<string> | functionlimit 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

ParamTypeDefaultDescription
stateStorageStateStorage
chatLogStorageChatLogStorage
notificationsNotifications
[acl]Array.<string> | functionlimit api to array of groups or use auth function
optionsobject
[options.stateTextFilter]TextFilteroptional funcion for filtering data in states
[options.mapper]Mappermapper for state values

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

ParamTypeDescription
argsobjectgql request
ctxObjectrequest context
aclArray.<string> | null | functioncustom 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

ParamType
[data]*
[errors]Array.<object>
 

RequestParams : object

Kind: global typedef

ParamType
[snapshot]string
 

PostBackAPI : object

Kind: global typedef
Properties

NameType
postBackfunction
 

ValidateBotAPI : object

Kind: global typedef
Properties

NameType
validateBotfunction
 

conversation : object

Kind: global typedef

 

StateStorage : object

Kind: global typedef
Properties

NameType
getStatesfunction
getStatefunction
 

ChatLogStorage : object

Kind: global typedef
Properties

NameType
getInteractionsfunction
 

TextFilter ⇒ any

Function for filtration of string output

Kind: global typedef

ParamType
valuestring
keystring