3.10.0 • Published 4 years ago

wingbot-botservice v3.10.0

Weekly downloads
13
License
MIT
Repository
github
Last release
4 years ago

Microsoft BotService plugin for wingbot.ai

const { Router, Bot } = require('wingbot');
const { BotService } = require('wingbot-botservice');

const bot = new Bot();

const processor = new Processor(bot);

const bs = new BotService(processor, {
    appId: '123',
    appSecret: '456'
});

// the route
module.exports.bot = async (req, res) => {
    const { body, headers } = req;

    await bs.verifyRequest(body, headers);

    await bs.processEvent(body);
};

Using backchannel for sending postBacks to the bot

const directLine = new DirectLine();
directLine.postActivity({
    type:'event',
    name:'postBack',
    from:{ id: botserviceUserId },
    value:{ action: 'action-path', data: {/* optional */} }
});

API

Classes

Functions

BotService

BotService connector for wingbot.ai

Kind: global class

new BotService(processor, options, senderLogger)

ParamTypeDefaultDescription
processorProcessorwingbot Processor instance
optionsObject
options.appIdstringbotservice client id
options.appSecretstringbotservice client secret
options.grantTypestringboservice authentication grant_type
options.scopestringboservice authentication scope
options.uristringboservice authentication uri
options.welcomeActionstring | null"'start'"conversation start emits postback
options.requestLibfunctionrequest library replacement for testing
options.overPublicstringoverride public key for testing
senderLoggerconsoleoptional console like chat logger

botService.processEvent(body) ⇒ Promise.<Array.<{message:Object, pageId:string}>>

Process Facebook request

Kind: instance method of BotService
Returns: Promise.<Array.<{message:Object, pageId:string}>> - - unprocessed events

ParamTypeDescription
bodybs.Activityevent body

botService.verifyRequest(body, headers) ⇒ Promise

Verify Facebook webhook event

Kind: instance method of BotService
Throws:

  • Error when authorization token is invalid or missing
ParamTypeDescription
bodyObjectparsed request body
headersObjectrequest headers

botServiceQuickReplyPatch(bot, startAction) ⇒ function

Patch, which solves problem with BotFramework. Always, when conversationId is changed, middleware looks for matching quick replies from first text request. When there are some, it redirects user

Kind: global function
Returns: function - - the middleware

ParamTypeDefaultDescription
botRouterchatbot itself
startActionstring"start"start action to fetch quick replies

Example

const { Router } = require('wingbot');
const { botServiceQuickReplyPatch } = require('wingbot-botservice');

const bot = new Router();

// attach as first
const patch = botServiceQuickReplyPatch(bot, 'start');
bot.use(patch);

bot.use('start', (req, res) => {
    res.text('Hello', {
        goto: 'Go to'
    });
});
3.10.0

4 years ago

3.9.1

4 years ago

3.9.0

4 years ago

3.9.0-alpha.5

4 years ago

3.9.0-alpha.4

4 years ago

3.9.0-alpha.3

4 years ago

3.9.0-alpha.2

4 years ago

3.9.0-alpha.1

4 years ago

3.8.2

5 years ago

3.8.1

5 years ago

3.8.0

5 years ago

3.7.0

5 years ago

2.2.0

5 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.1

6 years ago

2.0.1-alpha.3

6 years ago

2.0.1-alpha.2

6 years ago

2.0.1-alpha.1

6 years ago

2.0.0

7 years ago

1.4.0

7 years ago

1.4.0-alpha.2

7 years ago

1.4.0-alpha.1

7 years ago

1.3.1

7 years ago

1.3.0

7 years ago

1.2.0

7 years ago

1.1.6-alpha.1

7 years ago

1.1.5

7 years ago

1.1.4-alpha.4

7 years ago

1.1.4-alpha.3

7 years ago

1.1.4-alpha.2

7 years ago

1.1.4-alpha.1

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.0-alpha.13

7 years ago

1.0.0-alpha.11

7 years ago

1.0.0-alpha.10

7 years ago

1.0.0-alpha.9

7 years ago

1.0.0-alpha.8

7 years ago

1.0.0-alpha.7

7 years ago

1.0.0-alpha.6

7 years ago

1.0.0-alpha.5

7 years ago

1.0.0-alpha.4

7 years ago

1.0.0-alpha.3

7 years ago

1.0.0-alpha.2

7 years ago

1.0.0-alpha.1

7 years ago