Classes
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 - Logger :
object - PostBackAPI :
object - ValidateBotAPI :
object - conversation :
object - StateStorage :
object - ChatLogStorage :
object - TextFilter ⇒
any Function for filtration of string output
GraphApi
Kind: global class
new GraphApi(apis, options, [log])
| Param | Type | Default | 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 | |
| [options.auditLog] | AuditLog | ||
| [options.isProduction] | boolean | ||
| [options.hideVerboseErrors] | boolean | ||
| [log] | Logger | console |
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
| Param | Type |
|---|---|
| body | object |
| body.query | object |
| [body.variables] | object |
| [body.operationName] | string |
| headers | object |
| [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
| 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 FUNCTIONconst 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 | |
| [options.mapper] | Mapper | mapper 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
| 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> |
RequestParams : object
Kind: global typedef
| Param | Type |
|---|---|
| [snapshot] | string |
Logger : object
Kind: global typedef
Properties
| Name | Type |
|---|---|
| log | function |
| error | function |
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 |
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 |