Middleware

Description:
  • Configurable middleware for custom bot request handling. This module requires express.
Source:
Configurable middleware for custom bot request handling. This module requires express.

Classes

WebhookClient

Methods

(static) customComponent(service, options) → {external.ExpressApplication}

Description:
  • Create router middleware for custom component request handling.
Source:
Example
const OracleBot = require('@oracle/bots-node-sdk');
const express = require('express');

const app = express();
OracleBot.Middleware.customComponent(app, {
  baseUrl: '/components', // base url to attach endpoints
  cwd: __dirname, // root of application source
  register: [ // provide components and paths to register
    './path/to/a/directory',
    './path/to/a/component',
    require('./path/to/another/component'),
    './path/to/other/components',
  ]
});
Parameters:
Name Type Description
service external.ExpressApplication Application or router to attach custom component endpoints.
options Object Middleware configuration options.
Properties
Name Type Attributes Default Description
baseUrl string <optional>
'/' Base url for custom component endpoints
cwd string <optional>
process.cwd() Working directory from which any component paths are relative.
register Array.<string> | Array.<Object> | Array.<function()> Series of paths to components or directories, Objects with name=>component pairs, Objects representing a component, or Component class ctor Functions.
mixins * <optional>
Any mixin properties for CustomComponentContext
parser boolean | ParserOptions <optional>
{} Body parser middleware options. If false, parser will be ignored.
Returns:
- Application with service endpoints.
Type
external.ExpressApplication

(static) webhookReceiver(secret, callback)

Description:
  • Webhook middleware for receiving bot messages on a webhook channel. Note that it's essential to call OracleBot.init(app) to properly set body-parser middleware options upstream of the webhook receiver.
Source:
Deprecated:
Example
const OracleBot = require('@oracle/bots-node-sdk');
const express = require('express');
const app = express();
OracleBot.init(app); // must be applied upstream of the receiver for proper parsing.

const secret = process.env.BOT_WEBHOOK_SECRET; // can also be callback (req => string | Promise<string>)
app.post('/webhook/message', OracleBot.Middleware.webhookReceiver(secret, (req, res, next) => {
  const message = req.body;
  // Forward verified message to client...
  res.send(); // complete request
}));
Parameters:
Name Type Description
secret string | SecretKeyCallback Secret key for bot message validation
callback WebhookReceiverCallback Callback upon successful webhook message

Type Definitions

ExpressRequestHandler(req, res, nextopt)

Description:
  • Secret key request callback used in webhook message validation.
Source:
Example
const app = express();
app.get('/', (req, res, next) => {})
Parameters:
Name Type Attributes Description
req external:ExpressRequest Express request object
res external:ExpressResponse Express response object
next function <optional>
Express middleware next function

ParserOptions

Description:
  • Options used for express body-parser in bots custom middleware. Options are a subset of those available in body-parser, and cover most general use cases. If body-parser requirements extend beyond these general options, consider using the module:Util/Webhook.bodyParserRawMessageVerify function in your middleware configuration.
Source:
See:
Properties:
Name Type Attributes Default Description
json boolean | Object <optional>
true Parse json body payloads
urlencoded boolean | Object <optional>
true Parse urlencoded body payloads
limit string <optional>
'5mb' Parser body size limit
verify function <optional>
Additional body parser verification function
Options used for express body-parser in bots custom middleware. Options are a subset of those available in body-parser, and cover most general use cases. If body-parser requirements extend beyond these general options, consider using the module:Util/Webhook.bodyParserRawMessageVerify function in your middleware configuration.

ComponentMiddlewareOptions

Description:
  • Options for configuring bots custom component middleware.
Source:
Properties:
Name Type Attributes Default Description
baseUrl string <optional>
'/' Base url for custom component endpoints
cwd string <optional>
process.cwd() Working directory from which any component paths are relative.
register Array.<string> | Array.<Object> | Array.<function()> Series of paths to components or directories, Objects with name=>component pairs, Objects representing a component, or Component class ctor Functions.
mixins * <optional>
Any mixin properties for CustomComponentContext
Options for configuring bots custom component middleware.
Type:
  • Object