botbuilder-core
Version:
Core components for Microsoft Bot Builder. Components in this library can run either in a browser or on the server.
50 lines • 1.96 kB
JavaScript
;
/**
* @module botbuilder
*/
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RegisterClassMiddleware = void 0;
/**
* Middleware for adding an object to or registering a service with the current turn context.
*/
class RegisterClassMiddleware {
/**
* Initialize a new instance of the RegisterClassMiddleware class.
*
* @param service The object or service to add.
* @param key The key for service object in turn state.
*/
constructor(service, key) {
this.service = service;
this._key = key;
}
/**
* Adds the associated object or service to the current turn context.
*
* @param turnContext The context object for this turn.
* @param next The delegate to call to continue the bot middleware pipeline.
*/
onTurn(turnContext, next) {
return __awaiter(this, void 0, void 0, function* () {
turnContext.turnState.set(this._key, this.service);
if (next) {
yield next();
}
});
}
}
exports.RegisterClassMiddleware = RegisterClassMiddleware;
//# sourceMappingURL=registerClassMiddleware.js.map