chatpickle
Version:
Conversation Tests for Chatbots
46 lines • 2 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const lexruntime_1 = __importDefault(require("aws-sdk/clients/lexruntime"));
const lodash_get_1 = __importDefault(require("lodash.get"));
const BotClient_1 = require("./BotClient");
class LexClient extends BotClient_1.BotClient {
constructor(botContext, userContext) {
super(botContext, userContext);
this.botName = this.botContext.botName;
this.botAlias = this.botContext.botAlias;
this.userId = `${this.userContext.userId}-${Date.now()}`;
this.lastResponse = null;
this.sessionAttributes = this.userContext.userAttributes;
this.props = {
region: this.botContext.region,
};
// Optional Auth Environment Variables
this.props.accessKeyId = process.env.chatpickle_access_id || undefined;
this.props.secretAccessKey = process.env.chatpickle_access_secret || undefined;
this.lex = new lexruntime_1.default(this.props);
console.log(`[${this.userId}] New Conversation with ${this.botName}`);
}
async speak(inputText) {
console.log(`[${this.userId}] User: ${inputText}`);
const params = {
botName: this.botName,
botAlias: this.botAlias,
userId: this.userId,
inputText,
sessionAttributes: this.sessionAttributes,
};
this.lastResponse = await this.lex.postText(params).promise();
this.sessionAttributes = this.lastResponse.sessionAttributes;
const reply = this.lastResponse.message.trim();
console.log(`[${this.userId}] Bot: ${reply}`);
return reply;
}
async fetch(attributePath) {
return await lodash_get_1.default(this.lastResponse, attributePath);
}
}
exports.default = LexClient;
//# sourceMappingURL=LexClient.js.map