Skip to content

Commit b2ff429

Browse files
authored
Merge pull request #242 from watson-virtual-agents/dev
Dev
2 parents 56ceed1 + e299f7c commit b2ff429

File tree

23 files changed

+284
-90
lines changed

23 files changed

+284
-90
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ notifications:
2525
email:
2626
recipients:
2727
28-
- najimovi@ar.ibm.com
28+
- pedemont@us.ibm.com
2929
on_success: always # default is change, update if this gets too annoying
3030
on_failure: always # default: always
3131
addons:

dist/chat.js

Lines changed: 26 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/chat.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/chat.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/chat.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/lang/en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"en":{"prompt":"Enter message...","thinking":"Agent is thinking...","anything_else":"Is there anything else I can help you with?","list_sep":", ","reconnect":"Attempting to reconnect...","basic_err":"I am sorry, I am having difficulties.","loading_failure1":"<span class=\"IBMChat-loading-failure-message-text\">I cannot complete your request. You can try a new request or <a class=\"IBMChat-loading-retry-link\" data-retry=\"true\" href=\"javascript:void(false);\">restart the conversation.</a></span>","loading_failure2":"<span class=\"IBMChat-loading-failure-message-text\">I cannot complete your request. Please <a class=\"IBMChat-loading-retry-link\" data-retry=\"true\" href=\"javascript:void(false);\">restart the conversation.</a></span>","submit":"Submit","cancel":"Cancel","required_field":"This field is required.","placeholder_mon":"MM","placeholder_year":"YYYY","cc_name":"Name on Card","cc_num":"Credit Card Number","cc_exp_mon":"Expiration Date Month","cc_exp_year":"Expiration Date Year","cc_code":"CVV","cc_code_alt":"","cc_use_valid":"Please use a valid card. We accept the following: ","cc_invalid":"Your credit card number is invalid.","cc_invalid_exp":"Your credit card expiration date is invalid.","cc_invalid_code":"Your CVV is invalid.","loc_curr":"Current Location","postal_code":"Zip Code","loc_prompt":"Please share your current location.","loc_share":"Your browser is asking you to share your location...","loc_share_granted":"You have allowed your browser to share your current location.","loc_looking":"Looking up your current location...","loc_share_denied":"You have denied sharing your location on this website.","loc_not_shared_prompt":"Please enable location sharing or continue with your Zip Code.","loc_all":"All Locations","loc_closed_today":"Closed today.","loc_open_today":"Open today.","loc_open_today_more":"<span class=\"{ns}-hours-open\">Open today:</span><span class=\"{ns}-hours-today\"> {open, time, short} &ndash; {close, time, short}</span>","loc_hours_open":"<span class=\"{ns}-days-hours-day\">{openDay, date, weekday_short}:</span>&nbsp;<span class=\"{ns}-days-hours-hours\">{open, time, short} &ndash; {close, time, short}</span>","loc_hours_open_multiday":"<span class=\"{ns}-days-hours-day\">{openDay, date, weekday_short}&ndash;{closeDay, date, weekday_short}:</span>&nbsp;<span class=\"{ns}-days-hours-hours\">{open, time, short} &ndash; {close, time, short}</span>","loc_hours_unknown":"<span class=\"{ns}-days-hours-day\">{day, date, weekday_short}:</span>&nbsp;<span class=\"{ns}-days-hours-hours\">Hours unknown</span>","loc_hours_closed":"<span class=\"{ns}-days-hours-day\">{day, date, weekday_short}:</span>&nbsp;<span class=\"{ns}-days-hours-hours\">Closed</span>","loc_nearby_none":"We could not find any locations close to you.","loc_nearby_single":"Here are the details for this location:","loc_nearby_list":"Here are the locations I found close to you:","google_maps_url":"https://maps.google.com/"}}
1+
{"en":{"prompt":"Enter message...","thinking":"Agent is thinking...","anything_else":"Is there anything else I can help you with?","edit":"edit","list_sep":", ","reconnect":"Attempting to reconnect...","basic_err":"I am sorry, I am having difficulties.","loading_failure1":"<span class=\"IBMChat-loading-failure-message-text\">I cannot complete your request. You can try a new request or <a class=\"IBMChat-loading-retry-link\" data-retry=\"true\" href=\"javascript:void(false);\">restart the conversation.</a></span>","loading_failure2":"<span class=\"IBMChat-loading-failure-message-text\">I cannot complete your request. Please <a class=\"IBMChat-loading-retry-link\" data-retry=\"true\" href=\"javascript:void(false);\">restart the conversation.</a></span>","submit":"Submit","cancel":"Cancel","required_field":"This field is required.","placeholder_mon":"MM","placeholder_year":"YYYY","cc_name":"Name on Card","cc_num":"Credit Card Number","cc_exp_mon":"Expiration Date Month","cc_exp_year":"Expiration Date Year","cc_code":"CVV","cc_code_alt":"","cc_use_valid":"Please use a valid card. We accept the following: ","cc_invalid":"Your credit card number is invalid.","cc_invalid_exp":"Your credit card expiration date is invalid.","cc_invalid_code":"Your CVV is invalid.","loc_curr":"Current Location","postal_code":"Zip Code","loc_prompt":"Please share your current location.","loc_share":"Your browser is asking you to share your location...","loc_share_granted":"You have allowed your browser to share your current location.","loc_looking":"Looking up your current location...","loc_share_denied":"You have denied sharing your location on this website.","loc_not_shared_prompt":"Please enable location sharing or continue with your Zip Code.","loc_all":"All Locations","loc_closed_today":"Closed today.","loc_open_today":"Open today.","loc_open_today_more":"<span class=\"{ns}-hours-open\">Open today:</span><span class=\"{ns}-hours-today\"> {open, time, short} &ndash; {close, time, short}</span>","loc_hours_open":"<span class=\"{ns}-days-hours-day\">{openDay, date, weekday_short}:</span>&nbsp;<span class=\"{ns}-days-hours-hours\">{open, time, short} &ndash; {close, time, short}</span>","loc_hours_open_multiday":"<span class=\"{ns}-days-hours-day\">{openDay, date, weekday_short}&ndash;{closeDay, date, weekday_short}:</span>&nbsp;<span class=\"{ns}-days-hours-hours\">{open, time, short} &ndash; {close, time, short}</span>","loc_hours_unknown":"<span class=\"{ns}-days-hours-day\">{day, date, weekday_short}:</span>&nbsp;<span class=\"{ns}-days-hours-hours\">Hours unknown</span>","loc_hours_closed":"<span class=\"{ns}-days-hours-day\">{day, date, weekday_short}:</span>&nbsp;<span class=\"{ns}-days-hours-hours\">Closed</span>","loc_nearby_none":"We could not find any locations close to you.","loc_nearby_single":"Here are the details for this location:","loc_nearby_list":"Here are the locations I found close to you:","google_maps_url":"https://maps.google.com/"}}

examples/_mock_actions/langs.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"de": {
3+
"authorized_users": "Erika Mustermann und Max Mustermann",
4+
"agent": "Auf Ihrer Website würden Sie Code ausführen um jetzt mit einem Agent zu verbinden.",
5+
"account_settings": "Auf Ihrer Website würden Sie Code ausführen um jetzt die Kontoeinstellungen-Seite zu öffnen."
6+
},
7+
"en": {
8+
"authorized_users": "Bob Everyman and Jane Doe",
9+
"agent": "On your own site you would run code to connect to an agent now.",
10+
"account_settings": "On your own site you would run code to open the Account Settings page now."
11+
},
12+
"es": {
13+
"authorized_users": "Ana Sanchez y Juan Pérez",
14+
"agent": "En su sitio ejecutaría código para hablar con un agente.",
15+
"account_settings": "En su sitio ejecutaría código para abrir la pagina de Configuración de Cuentas."
16+
},
17+
"fr": {
18+
"authorized_users": "Jacques Martin et Marie Martin",
19+
"agent": "Sur votre site, vous exécuteriez le code pour vous connecter à un agent .",
20+
"account_settings": "Sur votre site, vous exécuteriez le code pour accéder à la page des paramètres du compte."
21+
},
22+
"it": {
23+
"authorized_users": "Mario Rossi e Maria Bianchi",
24+
"agent": "Sul tuo sito, normalmente ora eseguiresti codice che ti connette ad un agente",
25+
"account_settings": "Sul tuo sito, normalmente ora eseguiresti codice per mostrare i settaggi dell'account"
26+
},
27+
"pt-br": {
28+
"authorized_users": "João Silva e Maria Amélia",
29+
"agent": "No seu próprio site, você executaria código para conectar a um agente neste ponto",
30+
"account_settings": "No seu próprio site, você executaria código para exibir a página de Configurações de Conta neste ponto."
31+
}
32+
}

examples/_mock_actions/main.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
var langs = require('json!./langs.json');
2+
3+
var config = { instance: null };
4+
var userProfileVariablesMap = {};
5+
6+
function generateUserProfileVariablesMap() {
7+
userProfileVariablesMap = {
8+
'bill_amount': Number(42.01).toLocaleString(config.locale),
9+
'payment_due_date': (function() {
10+
const currentDate = new Date(new Date().getTime() + 24 * 60 * 60 * 1000);
11+
return currentDate.toLocaleDateString(config.locale);
12+
})(),
13+
'authorized_users': config.strings.authorized_users
14+
};
15+
}
16+
17+
function getUserProfileVariables(data) {
18+
const variables = data.message.action.args.variables;
19+
variables.forEach(function(v) {
20+
const value = userProfileVariablesMap[v];
21+
(value) ? config.instance.profile.set(v, value) : config.instance.profile.set(v, '[sample data]');
22+
});
23+
config.instance.sendSilently('success');
24+
}
25+
26+
function success() {
27+
return config.instance.sendSilently('success');
28+
}
29+
function agent() {
30+
return config.instance.receive(config.strings.agent);
31+
}
32+
function accountSettings() {
33+
return config.instance.receive(config.strings.account_settings);
34+
}
35+
36+
function registerActions(instance, locale, _skip) {
37+
config.instance = instance;
38+
config.locale = locale && locale.toLowerCase() || 'en';
39+
config.strings = langs[config.locale];
40+
generateUserProfileVariablesMap();
41+
42+
// subscribe to actions
43+
[
44+
['getUserProfileVariables', getUserProfileVariables],
45+
['updateAddress', success],
46+
['updateUserName', success],
47+
['updatePhoneNumber', success],
48+
['updateEmail', success],
49+
['payBill', success],
50+
['sendPaymentReceipt', success],
51+
['agent', agent],
52+
['openAccountSettingsPage', accountSettings]
53+
].forEach(function(action) {
54+
var name = action[0];
55+
var cb = action[1];
56+
if (_skip && _skip.indexOf(name) !== -1) { // skip
57+
return;
58+
}
59+
instance.subscribe('action:' + name, cb);
60+
});
61+
}
62+
63+
module.exports = {
64+
registerActions: registerActions
65+
};

examples/basic-actions-example/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Basic Custom Actions Example
22

3-
This example shows how to use "actions" as part of your flow in the chat widget. We will be using actions to update a users address.
3+
This example shows how to use "actions" as part of your flow in the chat widget. We will be using actions to update a users address. Simply type "update address" in the example and follow the prompts.
44

55
## Installing and Running Locally
66
1. set the `botID`, `XIBMClientID` and `XIBMClientSecret` parameters in [src/index.js](./src/index.js) (see [Getting Started](https://github.com/watson-virtual-agents/chat-widget/blob/master/README.md#getting-started) for further details on this):

examples/basic-actions-example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1",
88
"build": "webpack -minify -production",
9-
"start": "webpack-dev-server --port 3030"
9+
"start": "webpack-dev-server --host 0.0.0.0 --port 3030"
1010
},
1111
"license": "Apache-2.0",
1212
"author": "IBM Corp",

examples/basic-actions-example/src/index.js

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*/
1414

1515
var IBMChat = require('@watson-virtual-agent/chat-widget');
16+
var mockActions = require('../../_mock_actions/main.js');
1617

1718
// initialize chat widget. Set botID, XIBMClientID and XIBMClientSecret
1819
// with the corresponding values.
@@ -22,35 +23,39 @@ IBMChat.init({
2223
botID: '', // replace with Bot ID
2324
XIBMClientID: '', // replace with Client ID
2425
XIBMClientSecret: '' // replace with Client Secret
25-
});
26+
})
27+
.then(function() {
28+
// mock some actions in order to make the example for useful (but skip `updateAddress` -- see below)
29+
mockActions.registerActions(IBMChat, null, ['updateAddress']);
2630

27-
IBMChat.subscribe('action:updateAddress', function(data){
28-
var addressType = data.message.action.args.address_type;
29-
var address = {
30-
type: data.message.action.args.address_type, //e.g. billing or home. The user selected this by clicking a button
31-
/*
32-
when WVA called the form layout, it also included a "store" array to populate the form.
33-
when the form is submitted, the form data by the keys in the store array and added to
34-
IBMChat.profile. You can recall them from IBMChat.profile as below.
35-
*/
36-
address1: IBMChat.profile.get('user_street_address1'),
37-
address2: IBMChat.profile.get('user_street_address2'),
38-
city: IBMChat.profile.get('user_locality'),
39-
region: IBMChat.profile.get('user_state_or_province'),
40-
postalCode: IBMChat.profile.get('user_zipcode')
41-
}
42-
function error() {
43-
//IBMChat.sendSilently will send a message to WVA, but not show up in the chat console.
44-
// when there is an error, WVA expects you to respond with "failure". "success" and "cancel" are other potential options here.
45-
IBMChat.sendSilently('failure');
46-
}
47-
function success() {
48-
//IBMChat.sendSilently will send a message to WVA, but not show up in the chat console.
49-
// when everything goes as planned, WVA expects you to respond with "success". "failure" and "cancel" are other potential options here.
50-
IBMChat.sendSilently('success');
51-
}
52-
//send your data to your own datastore.
53-
myFakePostCommand(address, error, success);
31+
// add a custom action handle for `updateAddress`
32+
IBMChat.subscribe('action:updateAddress', function(data) {
33+
var address = {
34+
type: data.message.action.args.address_type, //e.g. billing or home. The user selected this by clicking a button
35+
/*
36+
when WVA called the form layout, it also included a "store" array to populate the form.
37+
when the form is submitted, the form data by the keys in the store array and added to
38+
IBMChat.profile. You can recall them from IBMChat.profile as below.
39+
*/
40+
address1: IBMChat.profile.get('user_street_address1'),
41+
address2: IBMChat.profile.get('user_street_address2'),
42+
city: IBMChat.profile.get('user_locality'),
43+
region: IBMChat.profile.get('user_state_or_province'),
44+
postalCode: IBMChat.profile.get('user_zipcode')
45+
};
46+
function error() {
47+
//IBMChat.sendSilently will send a message to WVA, but not show up in the chat console.
48+
// when there is an error, WVA expects you to respond with "failure". "success" and "cancel" are other potential options here.
49+
IBMChat.sendSilently('failure');
50+
}
51+
function success() {
52+
//IBMChat.sendSilently will send a message to WVA, but not show up in the chat console.
53+
// when everything goes as planned, WVA expects you to respond with "success". "failure" and "cancel" are other potential options here.
54+
IBMChat.sendSilently('success');
55+
}
56+
//send your data to your own datastore.
57+
myFakePostCommand(address, error, success);
58+
});
5459
});
5560

5661
function myFakePostCommand(data, errorCallback, successCallback) {
@@ -60,8 +65,15 @@ function myFakePostCommand(data, errorCallback, successCallback) {
6065
return true;
6166
return false;
6267
}
63-
if (isNotEmpty(data.type) && isNotEmpty(data.address1) && isNotEmpty(data.city) && isNotEmpty(data.region) && isNotEmpty(data.postalCode))
68+
if (isNotEmpty(data.type) &&
69+
isNotEmpty(data.address1) &&
70+
isNotEmpty(data.city) &&
71+
isNotEmpty(data.region) &&
72+
isNotEmpty(data.postalCode)) {
73+
console.log('Successfully updated user\'s address:', data);
6474
successCallback(); //let the WVA know everything went well
65-
else
75+
} else {
76+
console.error('There was an error updating user\'s address. Missing info.')
6677
errorCallback(); // let the WVA know that the attempt to save failed
78+
}
6779
}

examples/basic-custom-layout/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1",
88
"build": "webpack -minify -production",
9-
"start": "webpack-dev-server --port 3030"
9+
"start": "webpack-dev-server --host 0.0.0.0 --port 3030"
1010
},
1111
"license": "Apache-2.0",
1212
"author": "IBM Corp",

examples/basic-custom-layout/src/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*/
1414

1515
var IBMChat = require('@watson-virtual-agent/chat-widget');
16+
var mockActions = require('../../_mock_actions/main.js');
1617

1718
/**
1819
* This example shows how to create a custom layout to replace the chat widget's
@@ -157,4 +158,7 @@ IBMChat.init({
157158
botID: '', // replace with Bot ID
158159
XIBMClientID: '', // replace with Client ID
159160
XIBMClientSecret: '' // replace with Client Secret
161+
}).then(function() {
162+
// mock some actions in order to make the example for useful
163+
mockActions.registerActions(IBMChat);
160164
});

examples/basic-i18n-example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1",
88
"build": "webpack -minify -production",
9-
"start": "webpack-dev-server --port 3030"
9+
"start": "webpack-dev-server --host 0.0.0.0 --port 3030"
1010
},
1111
"license": "Apache-2.0",
1212
"author": "IBM Corp",

examples/basic-i18n-example/src/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818

1919
var IBMChat = require('@watson-virtual-agent/chat-widget');
20+
var mockActions = require('../../_mock_actions/main.js');
2021
// load a single or multi-language bundle of translated strings
2122
var langs = require('json-loader!@watson-virtual-agent/chat-widget/dist/lang/es.json');
2223
var locale = 'es';
@@ -36,4 +37,7 @@ IBMChat.init({
3637
botID: '', // replace with Bot ID
3738
XIBMClientID: '', // replace with Client ID
3839
XIBMClientSecret: '' // replace with Client Secret
40+
}).then(function() {
41+
// mock some actions in order to make the example for useful
42+
mockActions.registerActions(IBMChat, locale);
3943
});

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@watson-virtual-agent/chat-widget",
3-
"version": "1.6.0",
3+
"version": "1.6.1",
44
"description": "Watson Virtual Agent Chat Widget",
55
"homepage": "https://github.com/watson-virtual-agents/chat-widget",
66
"main": "dist/chat.js",
@@ -36,7 +36,7 @@
3636
"Watson Virtual Agent"
3737
],
3838
"license": "Apache-2.0",
39-
"publishConfig":{
39+
"publishConfig": {
4040
"registry": "https://registry.npmjs.org"
4141
},
4242
"author": "IBM Corp",
@@ -90,6 +90,7 @@
9090
"rewire": "2.5.2",
9191
"rewire-webpack": "1.0.1",
9292
"selenium-download": "2.0.7",
93+
"selfsigned": "1.9.1",
9394
"semver": "5.3.0",
9495
"sinon": "1.17.6",
9596
"sinon-chai": "2.8.0",

src/events/handlers/reset.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ var utils = require('../../utils');
55

66
function reset() {
77
events.publish('clear-error');
8+
events.publish('clear');
89
events.publish('scroll-to-bottom');
10+
events.publish('enable-loading');
911
return new window.Promise(function(resolve, reject) {
1012
var current = state.get();
1113
var SDKconfig = utils.getSDKConfig(current);
@@ -23,7 +25,6 @@ function reset() {
2325
.configure( SDKconfig )
2426
.start( current.botID )
2527
.then( function(res) {
26-
events.publish('clear');
2728
events.publish('chatID', res.chatID);
2829
events.publish('receive', res);
2930
})['catch']( function(err) {

src/events/handlers/try-it.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*/
1414

1515
var events = require('../../events');
16+
var i18n = require('../../utils/i18n');
1617
var state = require('../../state');
1718

1819
function _addDataSet(data) {
@@ -50,15 +51,18 @@ function layoutError(layout) {
5051

5152
function intent(data) {
5253
var element = data.element;
54+
var label = document.createElement('label');
5355
var link = document.createElement('a');
5456
link.setAttribute('href', 'javascript:void(0)');
57+
link.textContent = i18n('edit');
5558
if (data.private) {
56-
link.textContent = '#' + data.intent;
59+
label.textContent = '#' + data.intent;
5760
link.setAttribute('data-private', data.intent);
5861
} else {
59-
link.textContent = data.blueprint.label;
62+
label.textContent = data.blueprint.label;
6063
link.setAttribute('data-intent', _addDataSet(data));
6164
}
65+
element.appendChild(label);
6266
element.appendChild(link);
6367
}
6468

src/lang/en.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ en:
99
anything_else: 'Is there anything else I can help you with?'
1010

1111
# general
12+
edit: 'edit'
1213
## test: Currently only used when generating a list of credit cards (see `cc_use_valid`).
1314
list_sep: ', '
1415

0 commit comments

Comments
 (0)