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
- TextFilter ⇒
any
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 |
[options.auditLog] | AuditLog |
AuditLog
graphApi.auditLog : Kind: instance property of GraphApi
GqlLib
graphApi._gql ⇒ Kind: instance property of GraphApi
Promise.<GraphQlResponse>
graphApi.request(body, headers, [wingbotToken], [params]) ⇒ 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
postBackApi(processor, [acl]) ⇒ 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
validateBotApi(botFactory, [postBackTest], [textTest], [acl]) ⇒ 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
conversationsApi(stateStorage, chatLogStorage, notifications, [acl], options) ⇒ 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'});
boolean
apiAuthorizer(args, ctx, acl) ⇒ 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;}}}}
object
GraphQlResponse : Kind: global typedef
Param | Type |
---|---|
[data] | * |
[errors] | Array.<object> |
object
RequestParams : Kind: global typedef
Param | Type |
---|---|
[snapshot] | string |
object
PostBackAPI : Kind: global typedef
Properties
Name | Type |
---|---|
postBack | function |
object
ValidateBotAPI : Kind: global typedef
Properties
Name | Type |
---|---|
validateBot | function |
object
conversation : Kind: global typedef
object
StateStorage : Kind: global typedef
Properties
Name | Type |
---|---|
getStates | function |
getState | function |
object
ChatLogStorage : Kind: global typedef
Properties
Name | Type |
---|---|
getInteractions | function |
any
TextFilter ⇒ Function for filtration of string output
Kind: global typedef
Param | Type |
---|---|
value | string |
key | string |