Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

botbuilder

Package Overview
Dependencies
Maintainers
1
Versions
631
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

botbuilder - npm Package Compare versions

Comparing version 0.9.2 to 0.10.0

lib/Channel.js

5

lib/bots/BotConnectorBot.js

@@ -151,2 +151,3 @@ var __extends = (this && this.__extends) || function (d, b) {

_this.saveData(userId, sessionId, data, reply, function (err) {
var settings = ses.message.to.channelId == 'emulator' ? { endpoint: 'http://localhost:9000' } : _this.options;
if (res) {

@@ -167,3 +168,3 @@ _this.emit('reply', reply);

_this.emit('reply', reply);
post(_this.options, '/bot/v1.0/messages', reply, function (err) {
post(settings, '/bot/v1.0/messages', reply, function (err) {
if (err) {

@@ -178,3 +179,3 @@ _this.emit('error', err);

_this.emit('send', reply);
post(_this.options, '/bot/v1.0/messages', reply, function (err) {
post(settings, '/bot/v1.0/messages', reply, function (err) {
if (err) {

@@ -181,0 +182,0 @@ _this.emit('error', err);

1

lib/dialogs/EntityRecognizer.js

@@ -38,2 +38,3 @@ var utils = require('../utils');

switch (entity.resolution.resolution_type || entity.type) {
case 'builtin.datetime':
case 'builtin.datetime.date':

@@ -40,0 +41,0 @@ case 'builtin.datetime.time':

@@ -9,2 +9,4 @@ var __extends = (this && this.__extends) || function (d, b) {

var entities = require('./EntityRecognizer');
var mb = require('../Message');
var Channel = require('../Channel');
(function (PromptType) {

@@ -22,2 +24,4 @@ PromptType[PromptType["text"] = 0] = "text";

ListStyle[ListStyle["list"] = 2] = "list";
ListStyle[ListStyle["button"] = 3] = "button";
ListStyle[ListStyle["auto"] = 4] = "auto";
})(exports.ListStyle || (exports.ListStyle = {}));

@@ -114,5 +118,6 @@ var ListStyle = exports.ListStyle;

}
session.send(args.prompt);
session.send(this.formatPrompt(session, args));
};
Prompts.prototype.replyReceived = function (session) {
var _this = this;
var args = session.dialogData;

@@ -137,3 +142,3 @@ Prompts.options.recognizer.recognize({

args.maxRetries--;
session.send(args.retryPrompt || "I didn't understand. " + args.prompt);
session.send(_this.formatPrompt(session, args, true));
}

@@ -143,2 +148,81 @@ }

};
Prompts.prototype.formatPrompt = function (session, args, retry) {
if (retry === void 0) { retry = false; }
var prompt = args.prompt;
if (Array.isArray(prompt)) {
prompt = mb.Message.randomPrompt(prompt);
}
if (retry) {
if (args.retryPrompt) {
prompt = args.retryPrompt;
if (Array.isArray(prompt)) {
prompt = mb.Message.randomPrompt(prompt);
}
}
else if (typeof prompt == 'string') {
prompt = Prompts.options.defaultRetryPrompt + ' ' + prompt;
}
}
if (typeof prompt == 'string') {
var msg = new mb.Message();
if (args.promptType == PromptType.choice) {
var style = args.listStyle || ListStyle.auto;
if (style == ListStyle.auto) {
var maxBtns = Channel.maxButtons(session);
if (maxBtns > 0 && args.enumValues.length <= maxBtns) {
style = ListStyle.button;
}
else if (args.enumValues.length < 4) {
style = ListStyle.inline;
}
else {
style = ListStyle.list;
}
}
var connector = '', list;
switch (style) {
case ListStyle.button:
var a = { actions: [] };
for (var i = 0; i < session.dialogData.enumValues.length; i++) {
var action = session.dialogData.enumValues[i];
a.actions.push({ title: action, message: action });
}
msg.setText(session, prompt)
.addAttachment(a);
break;
case ListStyle.inline:
list = ' ';
args.enumValues.forEach(function (value, index) {
list += connector + (index + 1) + '. ' + value;
if (index == args.enumValues.length - 2) {
connector = index == 0 ? ' or ' : ', or ';
}
else {
connector = ', ';
}
});
msg.setText(session, prompt + '%s', list);
break;
case ListStyle.list:
list = '\n ';
args.enumValues.forEach(function (value, index) {
list += connector + (index + 1) + '. ' + value;
connector = '\n ';
});
msg.setText(session, prompt + '%s', list);
break;
default:
msg.setText(session, prompt);
break;
}
}
else {
msg.setText(session, prompt);
}
return msg;
}
else {
return prompt;
}
};
Prompts.configure = function (options) {

@@ -153,4 +237,4 @@ if (options) {

};
Prompts.text = function (ses, prompt) {
beginPrompt(ses, {
Prompts.text = function (session, prompt) {
beginPrompt(session, {
promptType: PromptType.text,

@@ -160,15 +244,15 @@ prompt: prompt

};
Prompts.number = function (ses, prompt, options) {
Prompts.number = function (session, prompt, options) {
var args = options || {};
args.promptType = PromptType.number;
args.prompt = prompt;
beginPrompt(ses, args);
beginPrompt(session, args);
};
Prompts.confirm = function (ses, prompt, options) {
Prompts.confirm = function (session, prompt, options) {
var args = options || {};
args.promptType = PromptType.confirm;
args.prompt = prompt;
beginPrompt(ses, args);
beginPrompt(session, args);
};
Prompts.choice = function (ses, prompt, choices, options) {
Prompts.choice = function (session, prompt, choices, options) {
var args = options || {};

@@ -178,3 +262,3 @@ args.promptType = PromptType.choice;

args.enumValues = entities.EntityRecognizer.expandChoices(choices);
args.listStyle = args.listStyle || ListStyle.list;
args.listStyle = args.listStyle || ListStyle.auto;
var connector = '', list;

@@ -204,12 +288,13 @@ switch (args.listStyle) {

}
beginPrompt(ses, args);
beginPrompt(session, args);
};
Prompts.time = function (ses, prompt, options) {
Prompts.time = function (session, prompt, options) {
var args = options || {};
args.promptType = PromptType.time;
args.prompt = prompt;
beginPrompt(ses, args);
beginPrompt(session, args);
};
Prompts.options = {
recognizer: new SimplePromptRecognizer()
recognizer: new SimplePromptRecognizer(),
defaultRetryPrompt: "I didn't understand."
};

@@ -219,4 +304,4 @@ return Prompts;

exports.Prompts = Prompts;
function beginPrompt(ses, args) {
ses.beginDialog(consts.DialogId.Prompts, args);
function beginPrompt(session, args) {
session.beginDialog(consts.DialogId.Prompts, args);
}

@@ -6,45 +6,94 @@ var request = require('request');

}
BotConnectorStorage.prototype.get = function (id, callback) {
BotConnectorStorage.prototype.get = function (address, callback) {
var ops = 2;
var settings = this.options;
var options = {
url: settings.endpoint + '/bot/v1.0/bots' + id
};
if (settings.appId && settings.appSecret) {
options.auth = {
username: settings.appId,
password: settings.appSecret
};
options.headers = {
'Ocp-Apim-Subscription-Key': settings.appSecret
};
}
request.get(options, function (err, response, body) {
try {
var data;
if (!err && typeof body === 'string') {
data = JSON.parse(body);
var data = {};
function read(path, field) {
if (path) {
var options = {
url: settings.endpoint + '/bot/v1.0/bots' + path
};
if (settings.appId && settings.appSecret) {
options.auth = {
username: settings.appId,
password: settings.appSecret
};
options.headers = {
'Ocp-Apim-Subscription-Key': settings.appSecret
};
}
callback(err, data);
request.get(options, function (err, response, body) {
if (!err) {
try {
data[field + 'Hash'] = body;
data[field] = typeof body === 'string' ? JSON.parse(body) : null;
}
catch (e) {
err = e instanceof Error ? e : new Error(e.toString());
}
}
if (callback && (err || --ops == 0)) {
callback(err, data);
callback = null;
}
});
}
catch (e) {
callback(e instanceof Error ? e : new Error(e.toString()), null);
else if (callback && --ops == 0) {
callback(null, data);
}
});
}
var userPath = address.userId ? '/users/' + address.userId : null;
var convoPath = address.conversationId ? '/conversations/' + address.conversationId + userPath : null;
read(userPath, 'userData');
read(convoPath, 'conversationData');
};
BotConnectorStorage.prototype.save = function (id, data, callback) {
BotConnectorStorage.prototype.save = function (address, data, callback) {
var ops = 2;
var settings = this.options;
var options = {
url: settings.endpoint + '/bot/v1.0/bots' + id,
body: data
};
if (settings.appId && settings.appSecret) {
options.auth = {
username: settings.appId,
password: settings.appSecret
};
options.headers = {
'Ocp-Apim-Subscription-Key': settings.appSecret
};
function write(path, field) {
if (path) {
var err;
var body;
var hashField = field + 'Hash';
try {
body = JSON.stringify(data[field]);
}
catch (e) {
err = e instanceof Error ? e : new Error(e.toString());
}
if (!err && (!data[hashField] || body !== data[hashField])) {
data[hashField] = body;
var options = {
url: settings.endpoint + '/bot/v1.0/bots' + path,
body: body
};
if (settings.appId && settings.appSecret) {
options.auth = {
username: settings.appId,
password: settings.appSecret
};
options.headers = {
'Ocp-Apim-Subscription-Key': settings.appSecret
};
}
request.post(options, function (err) {
if (callback && (err || --ops == 0)) {
callback(err);
callback = null;
}
});
}
else if (callback && (err || --ops == 0)) {
callback(err);
callback = null;
}
}
else if (callback && --ops == 0) {
callback(null);
}
}
request.post(options, callback);
var userPath = address.userId ? '/users/' + address.userId : null;
var convoPath = address.conversationId ? '/conversations/' + address.conversationId + userPath : null;
write(userPath, 'userData');
write(convoPath, 'conversationData');
};

@@ -51,0 +100,0 @@ return BotConnectorStorage;

@@ -5,3 +5,3 @@ {

"description": "Bot Builder is a dialog system for building rich bots on virtually any platform.",
"version": "0.9.2",
"version": "0.10.0",
"license": "MIT",

@@ -8,0 +8,0 @@ "keywords": [

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc