@butlerbot/sdk
Version:
The official ButlerBot SDK
38 lines (37 loc) • 1.73 kB
JavaScript
;
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.ButlerBotClient = void 0;
const conversation_1 = require("./modules/conversation");
class ButlerBotClient {
constructor(config) {
this.apiKey = config.apiKey;
this.serverUrl = config.serverUrl;
}
/** Checks the health of the server returning true if server is alive */
healthCheck() {
return __awaiter(this, arguments, void 0, function* (healthCheckPath = "/health") {
const url = `${this.serverUrl}${healthCheckPath}`;
try {
const response = yield fetch(url);
return response.ok;
}
catch (error) {
return false;
}
});
}
/** Spawns a new Conversation, inherits api key and server URL */
createConversation(config = {}) {
return new conversation_1.Conversation(Object.assign({ apiKey: this.apiKey, serverUrl: this.serverUrl }, config));
}
}
exports.ButlerBotClient = ButlerBotClient;