From 468af6db513856fb07c96da1da900321715cf515 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 11 Mar 2019 16:10:57 -0400 Subject: [PATCH 1/8] Add participant w/ out edge cases --- circuit-va.zip | Bin 15047 -> 23644 bytes circuitClient.js | 47 ++++----- index.js | 226 ++++++++++++++++++++++++++++++++++++------ package-lock.json | 248 +++++++++++++++++++++++----------------------- 4 files changed, 342 insertions(+), 179 deletions(-) diff --git a/circuit-va.zip b/circuit-va.zip index afd354264c9d3c883eb02c8dbead0de9e0637c46..338393479bf6d9289cd7565dc2d458ada8ca62c3 100644 GIT binary patch delta 17723 zcma*O1z6lk@-U3M27CxAw6A z&3%`}_;iOp9x?zhxrXR?i;AH;`hg9`vvCYgNS z5MphGpet1o0juM54LQ zEEp}`S|QER8_POSzxfB>s{@!Ms3wU*t{RCZBasaJ1)HB}!}+Url-CS1wa(uRdX|0+ zK!1Bq5UM=dmpc2x9b?2y(Sc44Fp!d7cI)v=D3=LXUzj9K7Fp#|Wzh~+`mxn3G^^oR z>pg(%7iIK`+ zRvr5(+K!=I85N^UqbA;zqO(jd)BZga`E-@oINPHG7uO;~$B3hj+~d@1iW;Y8Lw)xV zOpohnmtthWP31N7*fhUQ_wM~kt)a>}JKMm#kdfvCb#FCro30URzn8E++XV))(Rp890k~Rh(}>pAdez5=}lT7RICt)ya)}07_=Qba3vV*R5U*Jf&#N>tBV^8%CysnwRxw?I{g=Z3!+U z#ac2pMbpEJH+A=HLOy5y;2g2JGxY=`VC)a95~N>RhR|!nTPZ8=X2*<_AMbj6G6G5k zZXA;(PBLcMH03;lDak^^NZ!q8yMlp$&_IHK{FQMVp23_zAzoQGiJt;1DH?(dkjSst zCxj4s`xL3VtKEKvY>t6J(LB}bvG+c*v0RFTIRD9mfjHZ67z|&5@~G+YKA~%g=|+pt zWR#fG<6~WBqmb4o^S444Z`S$8Kbg3vQgKCAEck1h;?>R_@9r;JXh7X#mDtCvq$1XE z@x^7yerL5^D)v;s_3`d0b>^Df2I$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$D7e)PHfYBLC(B1tDYnmhnaS7c3hzt%VIWfeI2OqyeF7|08^$ zXiu;Bv+$A6i6O~fvrM5s&w>v!)_VOS6!VK@MY{+8{>uf&nk=JFXk)aXF{s~+lbKZj!pV! zU1XkhA^VGvk?eWL2tcaz2p~4ye-!_-zF_)`IG_B5*h`n}W%)l-XUe|_=_x@I%w(Xi zx)}e+o~us)RY>(>j9GoGmo0z3N;^QO`Z!RmG%w?12LDXT2t_hA^DJubv(G%kK!1F^ znO>BCFNXor)%eE%e_kk@e~>~z { return this.client.loggedOnUser; } + get: _ => { + return this.client.loggedOnUser; + } }); } - ///////////////////////////////////// /// Public functions ///////////////////////////////////// - async searchUsers (query) { + async searchUsers(query) { const self = this; return new Promise(async resolve => { let searchId; @@ -98,7 +100,7 @@ class CircuitClient { async function searchStatusHandler(evt) { // Indicates is search is finished - console.log('searchStatus', evt) + console.log('searchStatus', evt); if (evt.data.searchId !== searchId) { return; } @@ -116,19 +118,20 @@ class CircuitClient { self.client.addEventListener('basicSearchResults', searchResultHandler); self.client.addEventListener('searchStatus', searchStatusHandler); - searchId = await self.client.startBasicSearch([{ - scope: Circuit.Enums.SearchScope.CONVERSATIONS, - searchTerm: query - }]); + searchId = await self.client.startBasicSearch([ + { + scope: Circuit.Enums.SearchScope.CONVERSATIONS, + searchTerm: query + } + ]); }); } /** * logon */ - logon (accessToken) { - return this.client.logon(accessToken ? {accessToken: accessToken} : undefined) - .then(user => console.log(`Logged on to Circuit: ${user.displayName}`)) + logon(accessToken) { + return this.client.logon(accessToken ? { accessToken: accessToken } : undefined).then(user => console.log(`Logged on to Circuit: ${user.displayName}`)); } /** @@ -139,16 +142,14 @@ class CircuitClient { return Promise.resolve(); } const displayName = this.client.loggedOnUser.displayName; - return this.client.logout() - .then(_ => { - console.log(`Logged out of Circuit: ${displayName}`) - }); + return this.client.logout().then(_ => { + console.log(`Logged out of Circuit: ${displayName}`); + }); } ///////////////////////////////////// /// Private functions ///////////////////////////////////// - } -module.exports = CircuitClient; \ No newline at end of file +module.exports = CircuitClient; diff --git a/index.js b/index.js index 169d99e..e3bb974 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,4 @@ -'use strict' +'use strict'; const { dialogflow, Suggestions } = require('actions-on-google'); const express = require('express'); const bodyParser = require('body-parser'); @@ -6,14 +6,14 @@ const CircuitClient = require('./circuitClient'); // Client ID for IMPLICIT app on Circuit. Same ID needs to be defined // in Account Linking of your project at console.actions.google.com -const CLIENT_ID = 'd34edad8cda6433bb062f0671f58c232'; +const CLIENT_ID = ''; // Circuit session timeout const SESSION_TIMEOUT = 5 * 60 * 1000; // 5min session timeout const sessions = {}; // Active sessions -const app = dialogflow({clientId: CLIENT_ID}); +const app = dialogflow({ clientId: CLIENT_ID }); // Create express app to for handling the /_ah/start request posted // by AppEngine @@ -27,8 +27,7 @@ expressApp.get('/_ah/start', (req, res) => { expressApp.use(bodyParser.json(), app); // Start server -expressApp.listen(process.env.PORT || 8080); - +expressApp.listen(process.env.PORT || 8080, () => console.log('Listening at port 8080')); /** * Default Welcome Intent @@ -36,7 +35,7 @@ expressApp.listen(process.env.PORT || 8080); app.intent('Default Welcome Intent', conv => { // Create a session for this user at the beginning so user // is logged on to Circuit by the time needed - if (!sessions[conv.user.id]) { + if (!sessions[conv.user.storage]) { createSession(conv.user); } @@ -45,9 +44,175 @@ app.intent('Default Welcome Intent', conv => { }); /** - * message.send + * add.Participant + */ +app.intent('add.Participant', async (conv, { convName, user }) => { + const circuit = await getCircuit(conv); + if (!circuit) { + return; + } + + let users = await circuit.searchUsers(user); + let convs = await circuit.searchConversationsByName(convName); + + //Save results to context + conv.contexts.set('addparticipant_data', 5, { + users: users, + convs: convs + }); + + if (!users.length) { + //No user found + conv.ask(`I cannot find any user called ${user}. What's the name?`); + conv.contexts.set('addParticipant_getUser', 5); + return; + } else if (users.length > 1) { + // Multiple users found + users = users.slice(0, Math.min(7, users.length)); + const suggestions = users.map(u => u.displayName); + + conv.ask(`More than one user was found with the name ${user}. What's the full name?`, new Suggestions(suggestions)); + conv.contexts.set('addParticipant_getUser', 5); + return; + } + + if (!convs.length) { + //No conversation found + conv.ask(`I cannot find any conversation called ${convName}. What's the name?`); + conv.contexts.set('addParticipant_getConv', 5); + return; + } else if (convs.length > 1) { + // Multiple conversations found. + convs = convs.slice(0, Math.min(7, convs.length)); + const suggestions = convs.map(c => c.topic); + + conv.ask(`More than one conversation was found with the name ${convName}. What's the full name?`, new Suggestions(suggestions)); + conv.contexts.set('addParticipant_getConv', 5); + return; + } + + //One result found for user and conversation + conv.ask(`Ready to add ${users[0].displayName} to ${convs[0].topic}?`, new Suggestions('Yes', 'No')); +}); + +/** + * add.Participant - collect.conv + */ +app.intent('add.Participant - collect.conv', async conv => { + const circuit = await getCircuit(conv); + if (!circuit) { + return; + } + + const { users } = conv.contexts.input['addparticipant_data'].parameters; + let convName = conv.parameters.convName; + let convs = await circuit.searchConversationsByName(convName); + + if (!convs.length) { + //No conversation found + conv.ask(`I cannot find any conversation called ${convName}. What's the name?`); + return; + } else if (convs.length > 1) { + // Multiple conversations found. + convs = convs.slice(0, Math.min(7, convs.length)); + const suggestions = convs.map(c => c.topic); + + conv.ask(`More than one conversation was found with the name ${convName}. What's the full name?`, new Suggestions(suggestions)); + return; + } + + //Save conversation to context because only one found + conv.contexts.set('addparticipant_data', 5, { convs: convs }); + conv.contexts.delete('addParticipant_getConv'); + + //Users.length is always equal to one at this point + conv.ask(`Ready to add ${users[0].displayName} to ${convs[0].topic}?`, new Suggestions('Yes', 'No')); +}); + +/** + * add.Participant - collect.user + */ +app.intent('add.Participant - collect.user', async conv => { + const circuit = await getCircuit(conv); + if (!circuit) { + return; + } + + let { convs } = conv.contexts.input['addparticipant_data'].parameters; + let user = conv.parameters.user; + let users = await circuit.searchUsers(user); + + if (!users.length) { + //No user found + conv.ask(`I cannot find any user called ${user}. What's the name?`); + return; + } else if (users.length > 1) { + // Multiple users found + users = users.slice(0, Math.min(7, users.length)); + const suggestions = users.map(u => u.displayName); + + conv.ask(`More than one user was found with the name ${user}. What's the full name?`, new Suggestions(suggestions)); + conv.contexts.set('addParticipant_getUser', 5); + return; + } + + //Save user to context because only one found + conv.contexts.set('addparticipant_data', 5, { users: users }); + conv.contexts.delete('addParticipant_getUser'); + + if (!convs.length) { + //No conversation found + conv.ask(`Thank you. I did not find the conversation name that you gave me earlier. What is it again?`); + conv.contexts.set('addParticipant_getConv', 5); + return; + } else if (convs.length > 1) { + // Multiple conversations found. + convs = convs.slice(0, Math.min(7, convs.length)); + const suggestions = convs.map(c => c.topic); + + conv.ask(`Thank you. I found more than one result for the conversation name you gave me earlier. What's the full name?`, new Suggestions(suggestions)); + conv.contexts.set('addParticipant_getConv', 5); + return; + } + + //One result found for user and conversation + conv.ask(`Ready to add ${user} to ${convs[0].topic}?`, new Suggestions('Yes', 'No')); +}); + +/** + * add.Participant - no + */ +app.intent('add.Participant - no', async conv => { + const circuit = await getCircuit(conv); + if (!circuit) { + return; + } + + conv.ask('Is there anything else I can do for you?', new Suggestions('Yes', 'No')); + conv.contexts.delete('addparticipant_data'); + conv.contexts.set('anything_else', 2); +}); + +/** + * add.Participant - yes + */ +app.intent('add.Participant - yes', async conv => { + const circuit = await getCircuit(conv); + if (!circuit) { + return; + } + + const { users, convs } = conv.contexts.input['addparticipant_data'].parameters; + await circuit.addParticipant(convs[0].convId, users[0].userId, true); + conv.ask(`${users[0].displayName} was added to ${convs[0].topic}. Is there anything else I can do for you?`, new Suggestions('Yes', 'No')); + conv.contexts.delete('addparticipant_data'); + conv.contexts.set('anything_else', 2); +}); + +/** + * send.message */ -app.intent('send.message', async (conv, {target, message}) => { +app.intent('send.message', async (conv, { target, message }) => { const circuit = await getCircuit(conv); if (!circuit) { return; @@ -66,8 +231,8 @@ app.intent('send.message', async (conv, {target, message}) => { if (users.length + convs.length === 1) { // One result found. Ask user for confirmation. - const { convId } = users.length && await circuit.getDirectConversationWithUser(users[0].userId, true); - const name = users.length && users[0].displayName || convs[0].topic; + const { convId } = users.length && (await circuit.getDirectConversationWithUser(users[0].userId, true)); + const name = (users.length && users[0].displayName) || convs[0].topic; conv.ask(`Ready to send ${message} to ${name}?`, new Suggestions('Yes', `No, don't send it`)); conv.contexts.set('sendmessage_send', 5, { convId: convId || convs[0].convId @@ -83,7 +248,6 @@ app.intent('send.message', async (conv, {target, message}) => { conv.contexts.set('sendmessage_getconv', 5); conv.ask(`More than one user found with name ${target}. What's the full name?`, new Suggestions(suggestions)); - conv.ask(new Suggestions(suggestions)); }); /** @@ -102,9 +266,9 @@ app.intent('send.message - collect.target', async conv => { return; } - const { convId } = users.length && await circuit.getDirectConversationWithUser(users[0].userId, true); + const { convId } = users.length && (await circuit.getDirectConversationWithUser(users[0].userId, true)); const { message } = conv.contexts.input['sendmessage_data'].parameters; - const name = users.length && users[0].displayName || convs[0].topic; + const name = (users.length && users[0].displayName) || convs[0].topic; conv.ask(`Ready to send ${message} to ${name}?`, new Suggestions('Yes', `No, don't send it`)); conv.contexts.set('sendmessage_send', 5, { convId: convId || convs[0].convId @@ -124,7 +288,7 @@ app.intent('send.message - yes', async conv => { await circuit.addTextItem(convId, message); conv.contexts.delete('sendmessage_data'); conv.ask('Message sent. Is there anything else I can do for you?'); - conv.ask(new Suggestions('No, that\'s all', 'Yes')); + conv.ask(new Suggestions("No, that's all", 'Yes')); conv.contexts.set('anything_else', 2); }); @@ -134,14 +298,14 @@ app.intent('send.message - yes', async conv => { app.intent('send.message - no', async conv => { conv.contexts.delete('sendmessage_data'); conv.ask('Message not sent. Is there anything else I can do for you?'); - conv.ask(new Suggestions('No, that\'s all', 'Yes')); + conv.ask(new Suggestions("No, that's all", 'Yes')); conv.contexts.set('anything_else', 2); }); /** -* call.user -*/ -app.intent('call.user', async (conv, {target}) => { + * call.user + */ +app.intent('call.user', async (conv, { target }) => { const circuit = await getCircuit(conv); if (!circuit) { return; @@ -179,7 +343,7 @@ app.intent('call.user', async (conv, {target}) => { /** * call.user - collect target */ -app.intent('call.user - collect target', async (conv, {target}) => { +app.intent('call.user - collect target', async (conv, { target }) => { const circuit = await getCircuit(conv); if (!circuit) { return; @@ -236,11 +400,10 @@ app.intent('call.user - yes', async conv => { app.intent('call.user - no', async conv => { conv.contexts.delete('calluser_data'); conv.ask('Is there anything else I can do for you?'); - conv.ask(new Suggestions('No, that\'s all', 'Yes')); + conv.ask(new Suggestions("No, that's all", 'Yes')); conv.contexts.set('anything_else', 2); }); - /** * Common intents */ @@ -262,13 +425,12 @@ app.catch((conv, e) => { conv.close('Oops. Something went wrong.'); }); - /** * Get the circuit instance from the session. Create a new session if needed */ async function getCircuit(conv) { try { - const session = sessions[conv.user.id] || (await createSession(conv.user)); + const session = sessions[conv.user.storage] || (await createSession(conv.user)); return session.circuit; } catch (err) { conv.ask('No circuit session found. Start over please.'); @@ -280,13 +442,14 @@ async function getCircuit(conv) { * Create Circuit session */ function createSession(user) { - const circuit = new CircuitClient({client_id: CLIENT_ID}); - return circuit.logon(user.access.token) + const circuit = new CircuitClient({ client_id: CLIENT_ID }); + return circuit + .logon(user.access.token) .then(() => { const session = { circuit: circuit, timer: setTimeout(clearSession.bind(null, user.id), SESSION_TIMEOUT) - } + }; sessions[user.id] = session; return session; }) @@ -298,11 +461,9 @@ function createSession(user) { */ function findWebClient(circuit) { return circuit.getDevices().then(devices => { - return devices.find(device => { - return (device.clientId !== circuit.user.clientId) && - ((device.clientInfo.deviceType === 'WEB') || - (device.clientInfo.deviceType === 'APPLICATION' && device.clientInfo.deviceSubtype === 'DESKTOP_APP')); - }); + return devices.find(device => { + return device.clientId !== circuit.user.clientId && (device.clientInfo.deviceType === 'WEB' || (device.clientInfo.deviceType === 'APPLICATION' && device.clientInfo.deviceSubtype === 'DESKTOP_APP')); + }); }); } @@ -324,10 +485,9 @@ function clearSession(sessionId) { /** * destroy */ -function destroy() {; +function destroy() { let promises = []; Object.keys(sessions).forEach(key => promises.push(clearSession(key))); sessions = []; return Promise.all(promises); } - diff --git a/package-lock.json b/package-lock.json index 656c083..e82cc1c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,8 +14,8 @@ "resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.17.0.tgz", "integrity": "sha512-a2+YeUjPkztKJu5aIF2yArYFQQp8d51wZ7DavSHjFuY1mqVgidGyzEQ41JIVNy82fXj8yPgy2vJmfIywgESW6w==", "requires": { - "@types/connect": "3.4.32", - "@types/node": "9.6.38" + "@types/connect": "*", + "@types/node": "*" } }, "@types/connect": { @@ -23,7 +23,7 @@ "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.32.tgz", "integrity": "sha512-4r8qa0quOvh7lGD0pre62CAb1oni1OO6ecJLGCezTmhQ8Fz50Arx9RUszryR8KlgK6avuSXvviL6yWyViQABOg==", "requires": { - "@types/node": "9.6.38" + "@types/node": "*" } }, "@types/debug": { @@ -41,9 +41,9 @@ "resolved": "https://registry.npmjs.org/@types/express/-/express-4.16.0.tgz", "integrity": "sha512-TtPEYumsmSTtTetAPXlJVf3kEqb6wZK0bZojpJQrnD/djV4q1oB6QQ8aKvKqwNPACoe02GNiy5zDzcYivR5Z2w==", "requires": { - "@types/body-parser": "1.17.0", - "@types/express-serve-static-core": "4.16.0", - "@types/serve-static": "1.13.2" + "@types/body-parser": "*", + "@types/express-serve-static-core": "*", + "@types/serve-static": "*" } }, "@types/express-serve-static-core": { @@ -51,9 +51,9 @@ "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.16.0.tgz", "integrity": "sha512-lTeoCu5NxJU4OD9moCgm0ESZzweAx0YqsAcab6OB0EB3+As1OaHtKnaGJvcngQxYsi9UNv0abn4/DRavrRxt4w==", "requires": { - "@types/events": "1.2.0", - "@types/node": "9.6.38", - "@types/range-parser": "1.2.2" + "@types/events": "*", + "@types/node": "*", + "@types/range-parser": "*" } }, "@types/mime": { @@ -76,8 +76,8 @@ "resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.13.2.tgz", "integrity": "sha512-/BZ4QRLpH/bNYgZgwhKEh+5AsboDBcUdlBYgzoLX0fpj3Y2gp6EApyOlM3bK53wQS/OE1SrdSYBAbux2D1528Q==", "requires": { - "@types/express-serve-static-core": "4.16.0", - "@types/mime": "2.0.0" + "@types/express-serve-static-core": "*", + "@types/mime": "*" } }, "accepts": { @@ -85,7 +85,7 @@ "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.2.13.tgz", "integrity": "sha1-5fHzkoxtlf2WVYw27D2dDeSm7Oo=", "requires": { - "mime-types": "2.1.21", + "mime-types": "~2.1.6", "negotiator": "0.5.3" } }, @@ -94,13 +94,13 @@ "resolved": "https://registry.npmjs.org/actions-on-google/-/actions-on-google-2.4.1.tgz", "integrity": "sha512-1clTurCUolQMk5Yrwy9Jf+VIs3+S0EToHsRQEgCohjK3HmPjaG5aullk8pqWAKVFNgxrFaEGiGY0vhba6rg6rQ==", "requires": { - "@types/aws-lambda": "0.0.33", - "@types/debug": "0.0.30", - "@types/express": "4.16.0", - "@types/node": "9.6.38", - "debug": "3.2.6", - "google-auth-library": "1.6.1", - "googleapis": "27.0.0" + "@types/aws-lambda": "^0.0.33", + "@types/debug": "^0.0.30", + "@types/express": "^4.11.1", + "@types/node": "^9.4.6", + "debug": "^3.1.0", + "google-auth-library": "^1.3.2", + "googleapis": "^27.0.0" } }, "array-flatten": { @@ -118,8 +118,8 @@ "resolved": "http://registry.npmjs.org/axios/-/axios-0.18.0.tgz", "integrity": "sha1-MtU+SFHv3AoRmTts0AB4nXDAUQI=", "requires": { - "follow-redirects": "1.5.9", - "is-buffer": "1.1.6" + "follow-redirects": "^1.3.0", + "is-buffer": "^1.1.5" } }, "balanced-match": { @@ -139,15 +139,15 @@ "integrity": "sha1-WykhmP/dVTs6DyDe0FkrlWlVyLQ=", "requires": { "bytes": "3.0.0", - "content-type": "1.0.4", + "content-type": "~1.0.4", "debug": "2.6.9", - "depd": "1.1.2", - "http-errors": "1.6.3", + "depd": "~1.1.2", + "http-errors": "~1.6.3", "iconv-lite": "0.4.23", - "on-finished": "2.3.0", + "on-finished": "~2.3.0", "qs": "6.5.2", "raw-body": "2.3.3", - "type-is": "1.6.16" + "type-is": "~1.6.16" }, "dependencies": { "debug": { @@ -171,7 +171,7 @@ "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", "optional": true, "requires": { - "balanced-match": "1.0.0", + "balanced-match": "^1.0.0", "concat-map": "0.0.1" } }, @@ -185,10 +185,10 @@ "resolved": "https://registry.npmjs.org/bunyan/-/bunyan-1.8.12.tgz", "integrity": "sha1-8VDw9nSKvdcq6uhPBEA74u8RN5c=", "requires": { - "dtrace-provider": "0.8.7", - "moment": "2.22.2", - "mv": "2.1.1", - "safe-json-stringify": "1.2.0" + "dtrace-provider": "~0.8", + "moment": "^2.10.6", + "mv": "~2", + "safe-json-stringify": "~1" } }, "bytes": { @@ -201,7 +201,7 @@ "resolved": "https://registry.npmjs.org/circuit-sdk/-/circuit-sdk-1.2.4502.tgz", "integrity": "sha512-NixVbK5YXFL88b9Rli/+Ww/XUd0WD2lYKzeIuW/kkqVUpZds+9F9LGwPhyP9RqCqIvdQSKy7rVeGI3q0+ztH5Q==", "requires": { - "ws": "3.3.3" + "ws": "~3.3.3" } }, "concat-map": { @@ -235,7 +235,7 @@ "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz", "integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==", "requires": { - "ms": "2.1.1" + "ms": "^2.1.1" } }, "depd": { @@ -254,7 +254,7 @@ "integrity": "sha1-3JObTT4GIM/gwc2APQ0tftBP/QQ=", "optional": true, "requires": { - "nan": "2.11.1" + "nan": "^2.10.0" } }, "ecdsa-sig-formatter": { @@ -262,7 +262,7 @@ "resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.10.tgz", "integrity": "sha1-HFlQAPBKiJffuFAAiSoPTDOvhsM=", "requires": { - "safe-buffer": "5.1.2" + "safe-buffer": "^5.0.1" } }, "ee-first": { @@ -285,31 +285,31 @@ "resolved": "http://registry.npmjs.org/express/-/express-4.13.3.tgz", "integrity": "sha1-3bLx+0UCvzNZjSsDKwN5YMpsgKM=", "requires": { - "accepts": "1.2.13", + "accepts": "~1.2.12", "array-flatten": "1.1.1", "content-disposition": "0.5.0", - "content-type": "1.0.4", + "content-type": "~1.0.1", "cookie": "0.1.3", "cookie-signature": "1.0.6", - "debug": "2.2.0", - "depd": "1.0.1", + "debug": "~2.2.0", + "depd": "~1.0.1", "escape-html": "1.0.2", - "etag": "1.7.0", + "etag": "~1.7.0", "finalhandler": "0.4.0", "fresh": "0.3.0", "merge-descriptors": "1.0.0", - "methods": "1.1.2", - "on-finished": "2.3.0", - "parseurl": "1.3.2", + "methods": "~1.1.1", + "on-finished": "~2.3.0", + "parseurl": "~1.3.0", "path-to-regexp": "0.1.7", - "proxy-addr": "1.0.10", + "proxy-addr": "~1.0.8", "qs": "4.0.0", - "range-parser": "1.0.3", + "range-parser": "~1.0.2", "send": "0.13.0", - "serve-static": "1.10.3", - "type-is": "1.6.16", + "serve-static": "~1.10.0", + "type-is": "~1.6.6", "utils-merge": "1.0.0", - "vary": "1.0.1" + "vary": "~1.0.1" }, "dependencies": { "debug": { @@ -342,7 +342,7 @@ "resolved": "http://registry.npmjs.org/express-basic-auth/-/express-basic-auth-0.2.3.tgz", "integrity": "sha1-/hKr1bW4CEFEjSoZ62fGxBnmFdo=", "requires": { - "basic-auth": "1.1.0" + "basic-auth": "^1.0.4" } }, "extend": { @@ -355,10 +355,10 @@ "resolved": "http://registry.npmjs.org/finalhandler/-/finalhandler-0.4.0.tgz", "integrity": "sha1-llpS2ejQXSuFdUhUH7ibU6JJfZs=", "requires": { - "debug": "2.2.0", + "debug": "~2.2.0", "escape-html": "1.0.2", - "on-finished": "2.3.0", - "unpipe": "1.0.0" + "on-finished": "~2.3.0", + "unpipe": "~1.0.0" }, "dependencies": { "debug": { @@ -381,7 +381,7 @@ "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.9.tgz", "integrity": "sha512-Bh65EZI/RU8nx0wbYF9shkFZlqLP+6WT/5FnA3cE/djNSuKNHJEinGGZgu/cQEkeeb2GdFOgenAmn8qaqYke2w==", "requires": { - "debug": "3.1.0" + "debug": "=3.1.0" }, "dependencies": { "debug": { @@ -419,8 +419,8 @@ "resolved": "http://registry.npmjs.org/gcp-metadata/-/gcp-metadata-0.6.3.tgz", "integrity": "sha512-MSmczZctbz91AxCvqp9GHBoZOSbJKAICV7Ow/AIWSJZRrRchUd5NL1b2P4OfP+4m490BEUPhhARfpHdqCxuCvg==", "requires": { - "axios": "0.18.0", - "extend": "3.0.2", + "axios": "^0.18.0", + "extend": "^3.0.1", "retry-axios": "0.3.2" } }, @@ -430,11 +430,11 @@ "integrity": "sha1-DwiGD2oVUSey+t1PnOJLGqtuTSI=", "optional": true, "requires": { - "inflight": "1.0.6", - "inherits": "2.0.3", - "minimatch": "3.0.4", - "once": "1.4.0", - "path-is-absolute": "1.0.1" + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "2 || 3", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" } }, "google-auth-library": { @@ -442,13 +442,13 @@ "resolved": "https://registry.npmjs.org/google-auth-library/-/google-auth-library-1.6.1.tgz", "integrity": "sha512-jYiWC8NA9n9OtQM7ANn0Tk464do9yhKEtaJ72pKcaBiEwn4LwcGYIYOfwtfsSm3aur/ed3tlSxbmg24IAT6gAg==", "requires": { - "axios": "0.18.0", - "gcp-metadata": "0.6.3", - "gtoken": "2.3.0", - "jws": "3.1.5", - "lodash.isstring": "4.0.1", - "lru-cache": "4.1.3", - "retry-axios": "0.3.2" + "axios": "^0.18.0", + "gcp-metadata": "^0.6.3", + "gtoken": "^2.3.0", + "jws": "^3.1.5", + "lodash.isstring": "^4.0.1", + "lru-cache": "^4.1.3", + "retry-axios": "^0.3.2" } }, "google-p12-pem": { @@ -456,8 +456,8 @@ "resolved": "http://registry.npmjs.org/google-p12-pem/-/google-p12-pem-1.0.2.tgz", "integrity": "sha512-+EuKr4CLlGsnXx4XIJIVkcKYrsa2xkAmCvxRhX2HsazJzUBAJ35wARGeApHUn4nNfPD03Vl057FskNr20VaCyg==", "requires": { - "node-forge": "0.7.6", - "pify": "3.0.0" + "node-forge": "^0.7.4", + "pify": "^3.0.0" } }, "googleapis": { @@ -465,11 +465,11 @@ "resolved": "http://registry.npmjs.org/googleapis/-/googleapis-27.0.0.tgz", "integrity": "sha512-Cz0BRsZmewc21N50x5nAUW5cqaGhJ9ETQKZMGqGL4BxmCV7ETELazSqmNi4oCDeRwM4Iub/fIJWAWZk2i6XLCg==", "requires": { - "google-auth-library": "1.6.1", - "pify": "3.0.0", - "qs": "6.5.2", + "google-auth-library": "^1.3.1", + "pify": "^3.0.0", + "qs": "^6.5.1", "string-template": "1.0.0", - "uuid": "3.3.2" + "uuid": "^3.2.1" } }, "gtoken": { @@ -477,11 +477,11 @@ "resolved": "http://registry.npmjs.org/gtoken/-/gtoken-2.3.0.tgz", "integrity": "sha512-Jc9/8mV630cZE9FC5tIlJCZNdUjwunvlwOtCz6IDlaiB4Sz68ki29a1+q97sWTnTYroiuF9B135rod9zrQdHLw==", "requires": { - "axios": "0.18.0", - "google-p12-pem": "1.0.2", - "jws": "3.1.5", - "mime": "2.3.1", - "pify": "3.0.0" + "axios": "^0.18.0", + "google-p12-pem": "^1.0.0", + "jws": "^3.1.4", + "mime": "^2.2.0", + "pify": "^3.0.0" } }, "http-errors": { @@ -489,10 +489,10 @@ "resolved": "http://registry.npmjs.org/http-errors/-/http-errors-1.6.3.tgz", "integrity": "sha1-i1VoC7S+KDoLW/TqLjhYC+HZMg0=", "requires": { - "depd": "1.1.2", + "depd": "~1.1.2", "inherits": "2.0.3", "setprototypeof": "1.1.0", - "statuses": "1.5.0" + "statuses": ">= 1.4.0 < 2" } }, "iconv-lite": { @@ -500,7 +500,7 @@ "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.23.tgz", "integrity": "sha512-neyTUVFtahjf0mB3dZT77u+8O0QB89jFdnBkd5P1JgYPbPaia3gXXOVL2fq8VyU2gMMD7SaN7QukTB/pmXYvDA==", "requires": { - "safer-buffer": "2.1.2" + "safer-buffer": ">= 2.1.2 < 3" } }, "inflight": { @@ -509,8 +509,8 @@ "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", "optional": true, "requires": { - "once": "1.4.0", - "wrappy": "1.0.2" + "once": "^1.3.0", + "wrappy": "1" } }, "inherits": { @@ -535,7 +535,7 @@ "requires": { "buffer-equal-constant-time": "1.0.1", "ecdsa-sig-formatter": "1.0.10", - "safe-buffer": "5.1.2" + "safe-buffer": "^5.0.1" } }, "jws": { @@ -543,8 +543,8 @@ "resolved": "https://registry.npmjs.org/jws/-/jws-3.1.5.tgz", "integrity": "sha512-GsCSexFADNQUr8T5HPJvayTjvPIfoyJPtLQBwn5a4WZQchcrPMPMAWcC1AzJVRDKyD6ZPROPAxgv6rfHViO4uQ==", "requires": { - "jwa": "1.1.6", - "safe-buffer": "5.1.2" + "jwa": "^1.1.5", + "safe-buffer": "^5.0.1" } }, "lodash.isstring": { @@ -557,8 +557,8 @@ "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.3.tgz", "integrity": "sha512-fFEhvcgzuIoJVUF8fYr5KR0YqxD238zgObTps31YdADwPPAp82a4M8TrckkWyx7ekNlf9aBcVn81cFwwXngrJA==", "requires": { - "pseudomap": "1.0.2", - "yallist": "2.1.2" + "pseudomap": "^1.0.2", + "yallist": "^2.1.2" } }, "media-typer": { @@ -591,7 +591,7 @@ "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.21.tgz", "integrity": "sha512-3iL6DbwpyLzjR3xHSFNFeb9Nz/M8WDkX33t1GFQnFOllWk8pOrh/LSrB5OXlnlW5P9LH73X6loW/eogc+F5lJg==", "requires": { - "mime-db": "1.37.0" + "mime-db": "~1.37.0" } }, "minimatch": { @@ -600,7 +600,7 @@ "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", "optional": true, "requires": { - "brace-expansion": "1.1.11" + "brace-expansion": "^1.1.7" } }, "minimist": { @@ -635,9 +635,9 @@ "integrity": "sha1-rmzg1vbV4KT32JN5jQPB6pVZtqI=", "optional": true, "requires": { - "mkdirp": "0.5.1", - "ncp": "2.0.0", - "rimraf": "2.4.5" + "mkdirp": "~0.5.1", + "ncp": "~2.0.0", + "rimraf": "~2.4.0" } }, "nan": { @@ -674,8 +674,9 @@ "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "optional": true, "requires": { - "wrappy": "1.0.2" + "wrappy": "1" } }, "parseurl": { @@ -704,7 +705,7 @@ "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-1.0.10.tgz", "integrity": "sha1-DUCoL4Afw1VWfS7LZe/j8HfxIcU=", "requires": { - "forwarded": "0.1.2", + "forwarded": "~0.1.0", "ipaddr.js": "1.0.5" } }, @@ -745,7 +746,7 @@ "integrity": "sha1-7nEM5dk6j9uFb7Xqj/Di11k0sto=", "optional": true, "requires": { - "glob": "6.0.4" + "glob": "^6.0.1" } }, "safe-buffer": { @@ -769,18 +770,18 @@ "resolved": "https://registry.npmjs.org/send/-/send-0.13.0.tgz", "integrity": "sha1-UY+SGusFYK7H3KspkLFM9vPM5d4=", "requires": { - "debug": "2.2.0", - "depd": "1.0.1", + "debug": "~2.2.0", + "depd": "~1.0.1", "destroy": "1.0.3", "escape-html": "1.0.2", - "etag": "1.7.0", + "etag": "~1.7.0", "fresh": "0.3.0", - "http-errors": "1.3.1", + "http-errors": "~1.3.1", "mime": "1.3.4", "ms": "0.7.1", - "on-finished": "2.3.0", - "range-parser": "1.0.3", - "statuses": "1.2.1" + "on-finished": "~2.3.0", + "range-parser": "~1.0.2", + "statuses": "~1.2.1" }, "dependencies": { "debug": { @@ -801,8 +802,8 @@ "resolved": "http://registry.npmjs.org/http-errors/-/http-errors-1.3.1.tgz", "integrity": "sha1-GX4izevUGYWF6GlO9nhhl7ke2UI=", "requires": { - "inherits": "2.0.3", - "statuses": "1.2.1" + "inherits": "~2.0.1", + "statuses": "1" } }, "mime": { @@ -827,8 +828,8 @@ "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.10.3.tgz", "integrity": "sha1-zlpuzTEB/tXsCYJ9rCKpwpv7BTU=", "requires": { - "escape-html": "1.0.3", - "parseurl": "1.3.2", + "escape-html": "~1.0.3", + "parseurl": "~1.3.1", "send": "0.13.2" }, "dependencies": { @@ -855,8 +856,8 @@ "resolved": "http://registry.npmjs.org/http-errors/-/http-errors-1.3.1.tgz", "integrity": "sha1-GX4izevUGYWF6GlO9nhhl7ke2UI=", "requires": { - "inherits": "2.0.3", - "statuses": "1.2.1" + "inherits": "~2.0.1", + "statuses": "1" } }, "mime": { @@ -874,18 +875,18 @@ "resolved": "https://registry.npmjs.org/send/-/send-0.13.2.tgz", "integrity": "sha1-dl52B8gFVFK7pvCwUllTUJhgNt4=", "requires": { - "debug": "2.2.0", - "depd": "1.1.2", - "destroy": "1.0.4", - "escape-html": "1.0.3", - "etag": "1.7.0", + "debug": "~2.2.0", + "depd": "~1.1.0", + "destroy": "~1.0.4", + "escape-html": "~1.0.3", + "etag": "~1.7.0", "fresh": "0.3.0", - "http-errors": "1.3.1", + "http-errors": "~1.3.1", "mime": "1.3.4", "ms": "0.7.1", - "on-finished": "2.3.0", - "range-parser": "1.0.3", - "statuses": "1.2.1" + "on-finished": "~2.3.0", + "range-parser": "~1.0.3", + "statuses": "~1.2.1" } }, "statuses": { @@ -916,7 +917,7 @@ "integrity": "sha512-HRkVv/5qY2G6I8iab9cI7v1bOIdhm94dVjQCPFElW9W+3GeDOSHmy2EBYe4VTApuzolPcmgFTN3ftVJRKR2J9Q==", "requires": { "media-typer": "0.3.0", - "mime-types": "2.1.21" + "mime-types": "~2.1.18" } }, "ultron": { @@ -947,16 +948,17 @@ "wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", + "optional": true }, "ws": { "version": "3.3.3", "resolved": "https://registry.npmjs.org/ws/-/ws-3.3.3.tgz", "integrity": "sha512-nnWLa/NwZSt4KQJu51MYlCcSQ5g7INpOrOMt4XV8j4dqTXdmlUmSHQ8/oLC069ckre0fRsgfvsKwbTdtKLCDkA==", "requires": { - "async-limiter": "1.0.0", - "safe-buffer": "5.1.2", - "ultron": "1.1.1" + "async-limiter": "~1.0.0", + "safe-buffer": "~5.1.0", + "ultron": "~1.1.0" } }, "yallist": { From 010fd7f0a624b127f61501ad21fe8277ed889258 Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 13 Mar 2019 14:28:35 -0400 Subject: [PATCH 2/8] Add participant w/ edge cases --- index.js | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index e3bb974..72fe045 100644 --- a/index.js +++ b/index.js @@ -113,12 +113,17 @@ app.intent('add.Participant - collect.conv', async conv => { conv.ask(`I cannot find any conversation called ${convName}. What's the name?`); return; } else if (convs.length > 1) { - // Multiple conversations found. - convs = convs.slice(0, Math.min(7, convs.length)); - const suggestions = convs.map(c => c.topic); + //Multiple conversations found + let shortestConvName = [convs[0]]; + + //Loop through convs to find shortest conv name + convs.forEach(function(conv, i) { + if (conv.topic < shortestConvName[0].topic) { + shortestConvName[0] = conv; + } + }); - conv.ask(`More than one conversation was found with the name ${convName}. What's the full name?`, new Suggestions(suggestions)); - return; + convs = shortestConvName; } //Save conversation to context because only one found @@ -203,6 +208,24 @@ app.intent('add.Participant - yes', async conv => { } const { users, convs } = conv.contexts.input['addparticipant_data'].parameters; + const thisUser = circuit.user; + + if (convs[0].participants.indexOf(users[0].userId) !== -1) { + //User is already in the conversation + conv.ask(`${users[0].displayName} is already a participant in ${convs[0].topic}. Is there anything else I can do for you?`, new Suggestions('Yes', 'No')); + conv.contexts.delete('addparticipant_data'); + conv.contexts.set('anything_else', 2); + return; + } + + if (convs[0].isModerated && convs[0].moderators.indexOf(thisUser.userId) === -1) { + //Conversation is moderated and thisUser is not a moderator + conv.ask(`Sorry, but you are not a moderator in ${convs[0].topic} so ${users[0].displayName} cannot be added. Is there anything else I can do for you?`, new Suggestions('Yes', 'No')); + conv.contexts.delete('addparticipant_data'); + conv.contexts.set('anything_else', 2); + return; + } + await circuit.addParticipant(convs[0].convId, users[0].userId, true); conv.ask(`${users[0].displayName} was added to ${convs[0].topic}. Is there anything else I can do for you?`, new Suggestions('Yes', 'No')); conv.contexts.delete('addparticipant_data'); @@ -448,9 +471,9 @@ function createSession(user) { .then(() => { const session = { circuit: circuit, - timer: setTimeout(clearSession.bind(null, user.id), SESSION_TIMEOUT) + timer: setTimeout(clearSession.bind(null, user.storage), SESSION_TIMEOUT) }; - sessions[user.id] = session; + sessions[user.storage] = session; return session; }) .catch(err => console.error(`Unable to logon to Circuit`, err)); From e28349c2967c5b9754c448f5b3f53ce56e9ba5d5 Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 22 Mar 2019 11:09:06 -0400 Subject: [PATCH 3/8] Remove participant --- circuit-va.zip | Bin 23644 -> 34173 bytes circuitClient.js | 1 + index.js | 248 +++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 220 insertions(+), 29 deletions(-) diff --git a/circuit-va.zip b/circuit-va.zip index 338393479bf6d9289cd7565dc2d458ada8ca62c3..d4b0cf1459a8bb1435d3f2c8282b85a970aebaae 100644 GIT binary patch delta 15535 zcmbVzWmuKV_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Wq`_?5T}~+W@W=-7UU02=7IG1L%{D}Z2d^TF#sm|Y{#~r_FVk?UU=+6X~ z&bnU#!5O~eqQ{;WhY!BTgwM%@g2Q-FWBwzqKE@e9Ayk-!cSuXRQ$hy z?tn^-4N%dd@&c)GFSbxA*jfa92qpyvgi}7KaG(YQg>e`3`vk#!%E*uFtfRgDOgN16 zwUn=)fCo>LgFx8X;@>sHa~8wM!h}5|?m%ImS{C^L+;xC?Z2y7)3CagB<|1k{=;Y+y zb_{%?fFT_~Pk~d0iTr@!Rov5Tbnk_#07ibm(>PBVF$*LsaAWTeXO|&7_E#pbKM#C_ zPT5rpq7sp^IG29!x2Nx_6n@sF*8A)@%mkCN@FZ};yTC;OM!&7g!e=p5A%Zx}&sKr$ z6zsntKp@1GvlzD!HXP=5z05jxz{3&<+e7|c-vDZ!8tj0MB7o!3vrr~{FF72&WC=$JGFm(xarqPwItkI1|3Q22K?o&WiK*_u_Oq zXTRS(>n|%Aw$YKIo(7-fEdrt!&I-I&0r2E>-a2UiFYHk;1B3{;TP%e*K_=%wpfw%r Gum1qgpW@*F diff --git a/circuitClient.js b/circuitClient.js index 030a069..6954157 100644 --- a/circuitClient.js +++ b/circuitClient.js @@ -28,6 +28,7 @@ class CircuitClient { this.getDirectConversationWithUser = this.client.getDirectConversationWithUser; this.getStartedCalls = this.client.getStartedCalls; this.joinConference = this.client.joinConference; + this.removeParticipant = this.client.removeParticipant; this.sendClickToCallRequest = this.client.sendClickToCallRequest; // Properties diff --git a/index.js b/index.js index 72fe045..d4eff5e 100644 --- a/index.js +++ b/index.js @@ -44,9 +44,9 @@ app.intent('Default Welcome Intent', conv => { }); /** - * add.Participant + * add.participant.to.group */ -app.intent('add.Participant', async (conv, { convName, user }) => { +app.intent('add.participant.to.group', async (conv, { convName, user }) => { const circuit = await getCircuit(conv); if (!circuit) { return; @@ -56,7 +56,7 @@ app.intent('add.Participant', async (conv, { convName, user }) => { let convs = await circuit.searchConversationsByName(convName); //Save results to context - conv.contexts.set('addparticipant_data', 5, { + conv.contexts.set('addparticipantgroup_data', 5, { users: users, convs: convs }); @@ -64,7 +64,7 @@ app.intent('add.Participant', async (conv, { convName, user }) => { if (!users.length) { //No user found conv.ask(`I cannot find any user called ${user}. What's the name?`); - conv.contexts.set('addParticipant_getUser', 5); + conv.contexts.set('addparticipantgroup_getuser', 5); return; } else if (users.length > 1) { // Multiple users found @@ -72,14 +72,14 @@ app.intent('add.Participant', async (conv, { convName, user }) => { const suggestions = users.map(u => u.displayName); conv.ask(`More than one user was found with the name ${user}. What's the full name?`, new Suggestions(suggestions)); - conv.contexts.set('addParticipant_getUser', 5); + conv.contexts.set('addparticipantgroup_getuser', 5); return; } if (!convs.length) { //No conversation found conv.ask(`I cannot find any conversation called ${convName}. What's the name?`); - conv.contexts.set('addParticipant_getConv', 5); + conv.contexts.set('addparticipantgroup_getconv', 5); return; } else if (convs.length > 1) { // Multiple conversations found. @@ -87,7 +87,7 @@ app.intent('add.Participant', async (conv, { convName, user }) => { const suggestions = convs.map(c => c.topic); conv.ask(`More than one conversation was found with the name ${convName}. What's the full name?`, new Suggestions(suggestions)); - conv.contexts.set('addParticipant_getConv', 5); + conv.contexts.set('addparticipantgroup_getconv', 5); return; } @@ -96,15 +96,15 @@ app.intent('add.Participant', async (conv, { convName, user }) => { }); /** - * add.Participant - collect.conv + * add.participant.to.group - collect.conv */ -app.intent('add.Participant - collect.conv', async conv => { +app.intent('add.participant.to.group - collect.conv', async conv => { const circuit = await getCircuit(conv); if (!circuit) { return; } - const { users } = conv.contexts.input['addparticipant_data'].parameters; + const { users } = conv.contexts.input['addparticipantgroup_data'].parameters; let convName = conv.parameters.convName; let convs = await circuit.searchConversationsByName(convName); @@ -127,23 +127,23 @@ app.intent('add.Participant - collect.conv', async conv => { } //Save conversation to context because only one found - conv.contexts.set('addparticipant_data', 5, { convs: convs }); - conv.contexts.delete('addParticipant_getConv'); + conv.contexts.set('addparticipantgroup_data', 5, { convs: convs }); + conv.contexts.delete('addparticipantgroup_getconv'); //Users.length is always equal to one at this point conv.ask(`Ready to add ${users[0].displayName} to ${convs[0].topic}?`, new Suggestions('Yes', 'No')); }); /** - * add.Participant - collect.user + * add.participant.to.group - collect.user */ -app.intent('add.Participant - collect.user', async conv => { +app.intent('add.participant.to.group - collect.user', async conv => { const circuit = await getCircuit(conv); if (!circuit) { return; } - let { convs } = conv.contexts.input['addparticipant_data'].parameters; + let { convs } = conv.contexts.input['addparticipantgroup_data'].parameters; let user = conv.parameters.user; let users = await circuit.searchUsers(user); @@ -157,18 +157,18 @@ app.intent('add.Participant - collect.user', async conv => { const suggestions = users.map(u => u.displayName); conv.ask(`More than one user was found with the name ${user}. What's the full name?`, new Suggestions(suggestions)); - conv.contexts.set('addParticipant_getUser', 5); + conv.contexts.set('addparticipantgroup_getuser', 5); return; } //Save user to context because only one found - conv.contexts.set('addparticipant_data', 5, { users: users }); - conv.contexts.delete('addParticipant_getUser'); + conv.contexts.set('addparticipantgroup_data', 5, { users: users }); + conv.contexts.delete('addparticipantgroup_getuser'); if (!convs.length) { //No conversation found conv.ask(`Thank you. I did not find the conversation name that you gave me earlier. What is it again?`); - conv.contexts.set('addParticipant_getConv', 5); + conv.contexts.set('addparticipantgroup_getconv', 5); return; } else if (convs.length > 1) { // Multiple conversations found. @@ -176,7 +176,7 @@ app.intent('add.Participant - collect.user', async conv => { const suggestions = convs.map(c => c.topic); conv.ask(`Thank you. I found more than one result for the conversation name you gave me earlier. What's the full name?`, new Suggestions(suggestions)); - conv.contexts.set('addParticipant_getConv', 5); + conv.contexts.set('addparticipantgroup_getconv', 5); return; } @@ -185,35 +185,35 @@ app.intent('add.Participant - collect.user', async conv => { }); /** - * add.Participant - no + * add.participant.to.group - no */ -app.intent('add.Participant - no', async conv => { +app.intent('add.participant.to.group - no', async conv => { const circuit = await getCircuit(conv); if (!circuit) { return; } conv.ask('Is there anything else I can do for you?', new Suggestions('Yes', 'No')); - conv.contexts.delete('addparticipant_data'); + conv.contexts.delete('addparticipantgroup_data'); conv.contexts.set('anything_else', 2); }); /** - * add.Participant - yes + * add.participant.to.group - yes */ -app.intent('add.Participant - yes', async conv => { +app.intent('add.participant.to.group - yes', async conv => { const circuit = await getCircuit(conv); if (!circuit) { return; } - const { users, convs } = conv.contexts.input['addparticipant_data'].parameters; + const { users, convs } = conv.contexts.input['addparticipantgroup_data'].parameters; const thisUser = circuit.user; if (convs[0].participants.indexOf(users[0].userId) !== -1) { //User is already in the conversation conv.ask(`${users[0].displayName} is already a participant in ${convs[0].topic}. Is there anything else I can do for you?`, new Suggestions('Yes', 'No')); - conv.contexts.delete('addparticipant_data'); + conv.contexts.delete('addparticipantgroup_data'); conv.contexts.set('anything_else', 2); return; } @@ -221,14 +221,203 @@ app.intent('add.Participant - yes', async conv => { if (convs[0].isModerated && convs[0].moderators.indexOf(thisUser.userId) === -1) { //Conversation is moderated and thisUser is not a moderator conv.ask(`Sorry, but you are not a moderator in ${convs[0].topic} so ${users[0].displayName} cannot be added. Is there anything else I can do for you?`, new Suggestions('Yes', 'No')); - conv.contexts.delete('addparticipant_data'); + conv.contexts.delete('addparticipantgroup_data'); conv.contexts.set('anything_else', 2); return; } await circuit.addParticipant(convs[0].convId, users[0].userId, true); conv.ask(`${users[0].displayName} was added to ${convs[0].topic}. Is there anything else I can do for you?`, new Suggestions('Yes', 'No')); - conv.contexts.delete('addparticipant_data'); + conv.contexts.delete('addparticipantgroup_data'); + conv.contexts.set('anything_else', 2); +}); + +/** + * remove.participant + */ +app.intent('remove.participant', async (conv, { user, convName }) => { + const circuit = await getCircuit(conv); + if (!circuit) { + return; + } + + let users = await circuit.searchUsers(user); + let convs = await circuit.searchConversationsByName(convName); + + //Save results to context + conv.contexts.set('removeparticipant_data', 5, { + users: users, + convs: convs + }); + + if (!users.length) { + //No user found + conv.ask(`I cannot find any user called ${user}. What's the name?`); + conv.contexts.set('removeparticipant_getuser', 5); + return; + } else if (users.length > 1) { + // Multiple users found + users = users.slice(0, Math.min(7, users.length)); + const suggestions = users.map(u => u.displayName); + + conv.ask(`More than one user was found with the name ${user}. What's the full name?`, new Suggestions(suggestions)); + conv.contexts.set('removeparticipant_getuser', 5); + return; + } + + if (!convs.length) { + //No conversation found + conv.ask(`I cannot find any conversation called ${convName}. What's the name?`); + conv.contexts.set('removeparticipant_getconv', 5); + return; + } else if (convs.length > 1) { + // Multiple conversations found. + convs = convs.slice(0, Math.min(7, convs.length)); + const suggestions = convs.map(c => c.topic); + + conv.ask(`More than one conversation was found with the name ${convName}. What's the full name?`, new Suggestions(suggestions)); + conv.contexts.set('removeparticipant_getconv', 5); + return; + } + + //One result found for user and conversation + conv.ask(`Ready to remove ${users[0].displayName} from ${convs[0].topic}?`, new Suggestions('Yes', 'No')); +}); + +/** + * remove.participant - collect.conv + */ +app.intent('remove.participant - collect.conv', async conv => { + const circuit = await getCircuit(conv); + if (!circuit) { + return; + } + + const { users } = conv.contexts.input['removeparticipant_data'].parameters; + let convName = conv.parameters.convName; + let convs = await circuit.searchConversationsByName(convName); + + if (!convs.length) { + //No conversation found + conv.ask(`I cannot find any conversation called ${convName}. What's the name?`); + return; + } else if (convs.length > 1) { + //Multiple conversations found + let shortestConvName = [convs[0]]; + + //Loop through convs to find shortest conv name + convs.forEach(function(conv, i) { + if (conv.topic < shortestConvName[0].topic) { + shortestConvName[0] = conv; + } + }); + + convs = shortestConvName; + } + + //Save conversation to context because only one found + conv.contexts.set('removeparticipant_data', 5, { convs: convs }); + conv.contexts.delete('removeparticipant_getconv'); + + //Users.length is always equal to one at this point + conv.ask(`Ready to remove ${users[0].displayName} from ${convs[0].topic}?`, new Suggestions('Yes', 'No')); +}); + +/** + * remove.participant - collect.user + */ +app.intent('remove.participant - collect.user', async conv => { + const circuit = await getCircuit(conv); + if (!circuit) { + return; + } + + let { convs } = conv.contexts.input['removeparticipant_data'].parameters; + let user = conv.parameters.user; + let users = await circuit.searchUsers(user); + + if (!users.length) { + //No user found + conv.ask(`I cannot find any user called ${user}. What's the name?`); + return; + } else if (users.length > 1) { + // Multiple users found + users = users.slice(0, Math.min(7, users.length)); + const suggestions = users.map(u => u.displayName); + + conv.ask(`More than one user was found with the name ${user}. What's the full name?`, new Suggestions(suggestions)); + conv.contexts.set('removeparticipant_getuser', 5); + return; + } + + //Save user to context because only one found + conv.contexts.set('removeparticipant_data', 5, { users: users }); + conv.contexts.delete('removeparticipant_getuser'); + + if (!convs.length) { + //No conversation found + conv.ask(`Thank you. I did not find the conversation name that you gave me earlier. What is it again?`); + conv.contexts.set('removeparticipant_getconv', 5); + return; + } else if (convs.length > 1) { + // Multiple conversations found. + convs = convs.slice(0, Math.min(7, convs.length)); + const suggestions = convs.map(c => c.topic); + + conv.ask(`Thank you. I found more than one result for the conversation name you gave me earlier. What's the full name?`, new Suggestions(suggestions)); + conv.contexts.set('removeparticipant_getconv', 5); + return; + } + + //One result found for user and conversation + conv.ask(`Ready to remove ${user} from ${convs[0].topic}?`, new Suggestions('Yes', 'No')); +}); + +/** + * remove.participant - no + */ +app.intent('remove.participant - no', async conv => { + const circuit = await getCircuit(conv); + if (!circuit) { + return; + } + + conv.ask('Is there anything else I can do for you?', new Suggestions('Yes', 'No')); + conv.contexts.delete('removeparticipant_data'); + conv.contexts.set('anything_else', 2); +}); + +/** + * remove.participant - yes + */ +app.intent('remove.participant - yes', async conv => { + const circuit = await getCircuit(conv); + if (!circuit) { + return; + } + + const { users, convs } = conv.contexts.input['removeparticipant_data'].parameters; + const thisUser = circuit.user; + + if (convs[0].participants.indexOf(users[0].userId) === -1) { + //User is already in the conversation + conv.ask(`${users[0].displayName} is not a participant in ${convs[0].topic}. Is there anything else I can do for you?`, new Suggestions('Yes', 'No')); + conv.contexts.delete('removeparticipant_data'); + conv.contexts.set('anything_else', 2); + return; + } + + if (convs[0].isModerated && convs[0].moderators.indexOf(thisUser.userId) === -1) { + //Conversation is moderated and thisUser is not a moderator + conv.ask(`Sorry, but you are not a moderator in ${convs[0].topic} so ${users[0].displayName} cannot be removed. Is there anything else I can do for you?`, new Suggestions('Yes', 'No')); + conv.contexts.delete('removeparticipant_data'); + conv.contexts.set('anything_else', 2); + return; + } + + await circuit.removeParticipant(convs[0].convId, users[0].userId, true); + conv.ask(`${users[0].displayName} was removed from ${convs[0].topic}. Is there anything else I can do for you?`, new Suggestions('Yes', 'No')); + conv.contexts.delete('removeparticipant_data'); conv.contexts.set('anything_else', 2); }); @@ -249,6 +438,7 @@ app.intent('send.message', async (conv, { target, message }) => { if (!users.length && !convs.length) { conv.ask(`I cannot find any user or conversation called ${target}. What's the name?`); + conv.contexts.set('sendmessage_getconv', 5); return; } From 0eef73164f80d91b05185ce70acb8698e6526dcf Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 22 Mar 2019 17:02:15 -0400 Subject: [PATCH 4/8] Add participant 1-on-1 --- circuit-va.zip | Bin 34173 -> 38880 bytes index.js | 166 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 166 insertions(+) diff --git a/circuit-va.zip b/circuit-va.zip index d4b0cf1459a8bb1435d3f2c8282b85a970aebaae..4a66d9a58c8981d8d14e6c8e86094c81667cc704 100644 GIT binary patch delta 7886 zcmZ8`1z42L_x93=NQc0Zf^;_$($d|6($cXku)wmEbT8cqC@J95Au1v&(t?C^cY{)X zyZip$_mlr}?RA*@xzCw-&YYP!bM`70bG{anP*(#Bn*xB3j}H(kPa)LD6e_QOT7`)e z@Yi&-@H}iXgd~FIZqjwt%tiWpEJnA9crK#H!VOI zJXecvous8UwK_H1cZY}w*A_UPCxg#Akt zu^vSn%iE+y!k3d$E2DNf4$|3PS?qm5vN{BxC$K>UZ*Y=S2fD(@EU_tiT5z?(VraQ& z;j|tN&YK*tn58eiE0{3^T*}-nf0kM9M37DdJ zI}RIYwQ9J+9cRP;_>qh(N%G=3dHN`Xrs$68jUPQU^4Bu8eUyG6nF!*hi0jpm>Hawj z8fw~NQBm~Rvbnm|Xe-@-aUZ8y=)F6*RmMIR8!{K3%&DEP9Zf5G7~T z>r(Ue{KaVIhc;RHMlWeo9Bk{gSG@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{tOl}pxGeoG0S*I#~4 z0bp*d!bPB@0^p*$5Rd*l@Ea-!4bUXMhg^VnR)@g@APW9zonm0^QjAC6je?Ukgm^h1HXBA<7%-v-Ef-5k3kV{a>cRgU LaTMxN46^zU8P%0P diff --git a/index.js b/index.js index d4eff5e..5fb9a3a 100644 --- a/index.js +++ b/index.js @@ -232,6 +232,172 @@ app.intent('add.participant.to.group - yes', async conv => { conv.contexts.set('anything_else', 2); }); +/** + * add.participant.to.one + */ +app.intent('add.participant.to.one', async (conv, { thirdUser, target }) => { + const circuit = await getCircuit(conv); + if (!circuit) { + return; + } + + let thirdUsers = await circuit.searchUsers(thirdUser); + let targetUsers = await circuit.searchUsers(target); + + //Save results to context + conv.contexts.set('addparticipantone_data', 5, { + thirdUsers: thirdUsers, + targetUsers: targetUsers + }); + + if (!thirdUsers.length) { + //No user found + conv.ask(`I cannot find any user called ${thirdUser}. What's the name?`); + conv.contexts.set('addparticipantone_getuser', 5); + return; + } else if (thirdUsers.length > 1) { + // Multiple users found + thirdUsers = thirdUsers.slice(0, Math.min(7, thirdUsers.length)); + const suggestions = thirdUsers.map(u => u.displayName); + + conv.ask(`More than one user was found with the name ${thirdUser}. What's the full name?`, new Suggestions(suggestions)); + conv.contexts.set('addparticipantone_getuser', 5); + return; + } + + if (!targetUsers.length) { + //No user found + conv.ask(`I cannot find any user called ${thirdUser}. What's the name?`); + conv.contexts.set('addparticipantone_getuser', 5); + return; + } else if (targetUsers.length > 1) { + // Multiple users found + targetUsers = targetUsers.slice(0, Math.min(7, targetUsers.length)); + const suggestions = targetUsers.map(u => u.displayName); + + conv.ask(`More than one user was found with the name ${target}. What's the full name?`, new Suggestions(suggestions)); + conv.contexts.set('addparticipantone_getuser', 5); + return; + } + + //One result found for thirdUser and target + conv.ask(`Ready to add ${thirdUsers[0].displayName} to your conversation with ${targetUsers[0].displayName}?`, new Suggestions('Yes', 'No')); +}); + +/** + * add.participant.to.one - collect.user + */ +app.intent('add.participant.to.one - collect.user', async conv => { + const circuit = await getCircuit(conv); + if (!circuit) { + return; + } + + let { thirdUsers, targetUsers } = conv.contexts.input['addparticipantone_data'].parameters; + let user = conv.parameters.user; + let users = await circuit.searchUsers(user); + + if (!users.length) { + //No user found + conv.ask(`I cannot find any user called ${user}. What's the name?`); + return; + } else if (users.length > 1) { + // Multiple users found + users = users.slice(0, Math.min(7, users.length)); + const suggestions = users.map(u => u.displayName); + + conv.ask(`More than one user was found with the name ${user}. What's the full name?`, new Suggestions(suggestions)); + return; + } + + //One user found beyond this point + let params = conv.contexts.output['addparticipantone_data'].parameters; + + if (thirdUsers.length !== 1 && !targetUsers.length) { + params = conv.contexts.output['addparticipantone_data'].parameters; + + //Add thirdUser to context + params.thirdUsers = [users[0]]; + conv.contexts.set('addparticipantone_data', 5, params); + + conv.ask(`Thank you. I couldn't find the user whose conversation you wanted me to add ${users[0].displayName} to. What's the name again?`); + return; + } + + if (thirdUsers.length !== 1 && targetUsers.length > 1) { + params = conv.contexts.input['addparticipantone_data'].parameters; + + //Add thirdUser to context + params.thirdUsers = [users[0]]; + conv.contexts.set('addparticipantone_data', 5, params); + + let tempUsers = targetUsers.slice(0, Math.min(7, targetUsers.length)); + const suggestions = tempUsers.map(u => u.displayName); + + conv.ask(`Thank you. I found more than one user whose conversation you wanted me to add ${users[0].displayName} to. What's the full name?`, new Suggestions(suggestions)); + return; + } + + if (targetUsers.length !== 1) { + params = conv.contexts.input['addparticipantone_data'].parameters; + + //Add targetUser to context + params.targetUsers = [users[0]]; + conv.contexts.set('addparticipantone_data', 5, params); + } + + conv.ask(`Ready to add ${thirdUsers[0].displayName} to your conversation with ${users[0].displayName}?`, new Suggestions('Yes', 'No')); +}); + +/** + * add.participant.to.one - no + */ +app.intent('add.participant.to.one - no', async conv => { + const circuit = await getCircuit(conv); + if (!circuit) { + return; + } + + conv.ask('Is there anything else I can do for you?', new Suggestions('Yes', 'No')); + conv.contexts.delete('addparticipantone_data'); + conv.contexts.set('anything_else', 2); +}); + +/** + * add.participant.to.one - yes + */ +app.intent('add.participant.to.one - yes', async conv => { + const circuit = await getCircuit(conv); + if (!circuit) { + return; + } + + const { thirdUsers, targetUsers } = conv.contexts.input['addparticipantone_data'].parameters; + const conversation = await circuit.getDirectConversationWithUser(targetUsers[0].userId); + + if (!conversation) { + //No direct conversation found + conv.ask(`You are not in a direct conversation with ${targetUsers[0].displayName}. Is there anything else I can do for you?`, new Suggestions('Yes', 'No')); + conv.contexts.delete('addparticipantone_data'); + conv.contexts.set('anything_else', 2); + return; + } + + if (thirdUsers[0].userId === targetUsers[0].userId) { + //thirdUser and targetUser is the same user + conv.ask(`I cannot add ${thirdUsers[0].displayName} to his own conversation. Is there anything else I can do for you?`, new Suggestions('Yes', 'No')); + conv.contexts.delete('addparticipantone_data'); + conv.contexts.set('anything_else', 2); + return; + } + + await circuit.addParticipant(conversation.convId, thirdUsers[0].userId); + + conv.ask(`${thirdUsers[0].displayName} has been added to your conversation with ${targetUsers[0].displayName}. Is there anything else I can do for you?`, new Suggestions('Yes', 'No')); + conv.contexts.delete('addparticipantone_data'); + conv.contexts.set('anything_else', 2); +}); + /** * remove.participant */ From 2ab54d5afeccfc3b719d58636ddb2017c4778d0d Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 27 Mar 2019 16:57:09 -0400 Subject: [PATCH 5/8] Cleanup --- index.js | 186 +++++++++++++++++-------------------------------------- 1 file changed, 58 insertions(+), 128 deletions(-) diff --git a/index.js b/index.js index 5fb9a3a..fcf62be 100644 --- a/index.js +++ b/index.js @@ -52,7 +52,7 @@ app.intent('add.participant.to.group', async (conv, { convName, user }) => { return; } - let users = await circuit.searchUsers(user); + let users = await getUsers(circuit, conv, user); let convs = await circuit.searchConversationsByName(convName); //Save results to context @@ -61,17 +61,7 @@ app.intent('add.participant.to.group', async (conv, { convName, user }) => { convs: convs }); - if (!users.length) { - //No user found - conv.ask(`I cannot find any user called ${user}. What's the name?`); - conv.contexts.set('addparticipantgroup_getuser', 5); - return; - } else if (users.length > 1) { - // Multiple users found - users = users.slice(0, Math.min(7, users.length)); - const suggestions = users.map(u => u.displayName); - - conv.ask(`More than one user was found with the name ${user}. What's the full name?`, new Suggestions(suggestions)); + if (users.length !== 1) { conv.contexts.set('addparticipantgroup_getuser', 5); return; } @@ -145,19 +135,10 @@ app.intent('add.participant.to.group - collect.user', async conv => { let { convs } = conv.contexts.input['addparticipantgroup_data'].parameters; let user = conv.parameters.user; - let users = await circuit.searchUsers(user); + let users = await getUsers(circuit, conv, user); - if (!users.length) { - //No user found - conv.ask(`I cannot find any user called ${user}. What's the name?`); - return; - } else if (users.length > 1) { - // Multiple users found - users = users.slice(0, Math.min(7, users.length)); - const suggestions = users.map(u => u.displayName); - - conv.ask(`More than one user was found with the name ${user}. What's the full name?`, new Suggestions(suggestions)); - conv.contexts.set('addparticipantgroup_getuser', 5); + if (users.length !== 1) { + //Stays in this intent and gets input from user again return; } @@ -241,41 +222,22 @@ app.intent('add.participant.to.one', async (conv, { thirdUser, target }) => { return; } - let thirdUsers = await circuit.searchUsers(thirdUser); - let targetUsers = await circuit.searchUsers(target); - //Save results to context conv.contexts.set('addparticipantone_data', 5, { thirdUsers: thirdUsers, targetUsers: targetUsers }); - if (!thirdUsers.length) { - //No user found - conv.ask(`I cannot find any user called ${thirdUser}. What's the name?`); - conv.contexts.set('addparticipantone_getuser', 5); - return; - } else if (thirdUsers.length > 1) { - // Multiple users found - thirdUsers = thirdUsers.slice(0, Math.min(7, thirdUsers.length)); - const suggestions = thirdUsers.map(u => u.displayName); + let thirdUsers = await getUsers(circuit, conv, thirdUser); - conv.ask(`More than one user was found with the name ${thirdUser}. What's the full name?`, new Suggestions(suggestions)); + if (thirdUsers.length !== 1) { conv.contexts.set('addparticipantone_getuser', 5); return; } - if (!targetUsers.length) { - //No user found - conv.ask(`I cannot find any user called ${thirdUser}. What's the name?`); - conv.contexts.set('addparticipantone_getuser', 5); - return; - } else if (targetUsers.length > 1) { - // Multiple users found - targetUsers = targetUsers.slice(0, Math.min(7, targetUsers.length)); - const suggestions = targetUsers.map(u => u.displayName); + let targetUsers = await getUsers(circuit, conv, target); - conv.ask(`More than one user was found with the name ${target}. What's the full name?`, new Suggestions(suggestions)); + if (targetUsers.length !== 1) { conv.contexts.set('addparticipantone_getuser', 5); return; } @@ -295,26 +257,18 @@ app.intent('add.participant.to.one - collect.user', async conv => { let { thirdUsers, targetUsers } = conv.contexts.input['addparticipantone_data'].parameters; let user = conv.parameters.user; - let users = await circuit.searchUsers(user); - - if (!users.length) { - //No user found - conv.ask(`I cannot find any user called ${user}. What's the name?`); - return; - } else if (users.length > 1) { - // Multiple users found - users = users.slice(0, Math.min(7, users.length)); - const suggestions = users.map(u => u.displayName); + let users = await getUsers(circuit, conv, user); - conv.ask(`More than one user was found with the name ${user}. What's the full name?`, new Suggestions(suggestions)); + if (users.length !== 1) { + //Stays in this intent and gets input from user again return; } //One user found beyond this point - let params = conv.contexts.output['addparticipantone_data'].parameters; + let params = conv.contexts.input['addparticipantone_data'].parameters; if (thirdUsers.length !== 1 && !targetUsers.length) { - params = conv.contexts.output['addparticipantone_data'].parameters; + params = conv.contexts.input['addparticipantone_data'].parameters; //Add thirdUser to context params.thirdUsers = [users[0]]; @@ -407,7 +361,7 @@ app.intent('remove.participant', async (conv, { user, convName }) => { return; } - let users = await circuit.searchUsers(user); + let users = await getUsers(circuit, conv, user); let convs = await circuit.searchConversationsByName(convName); //Save results to context @@ -416,17 +370,7 @@ app.intent('remove.participant', async (conv, { user, convName }) => { convs: convs }); - if (!users.length) { - //No user found - conv.ask(`I cannot find any user called ${user}. What's the name?`); - conv.contexts.set('removeparticipant_getuser', 5); - return; - } else if (users.length > 1) { - // Multiple users found - users = users.slice(0, Math.min(7, users.length)); - const suggestions = users.map(u => u.displayName); - - conv.ask(`More than one user was found with the name ${user}. What's the full name?`, new Suggestions(suggestions)); + if (users.length !== 1) { conv.contexts.set('removeparticipant_getuser', 5); return; } @@ -500,19 +444,10 @@ app.intent('remove.participant - collect.user', async conv => { let { convs } = conv.contexts.input['removeparticipant_data'].parameters; let user = conv.parameters.user; - let users = await circuit.searchUsers(user); + let users = await getUsers(circuit, conv, user); - if (!users.length) { - //No user found - conv.ask(`I cannot find any user called ${user}. What's the name?`); - return; - } else if (users.length > 1) { - // Multiple users found - users = users.slice(0, Math.min(7, users.length)); - const suggestions = users.map(u => u.displayName); - - conv.ask(`More than one user was found with the name ${user}. What's the full name?`, new Suggestions(suggestions)); - conv.contexts.set('removeparticipant_getuser', 5); + if (users.length !== 1) { + //Stays in this intent and gets input from user again return; } @@ -690,33 +625,20 @@ app.intent('call.user', async (conv, { target }) => { return; } - let users = await circuit.searchUsers(target); + let users = await getUsers(circuit, conv, target); - if (!users.length) { + if (users.length !== 1) { conv.contexts.set('calluser_getuser', 5); - conv.ask(`I cannot find any user called ${target}. What's the name?`); return; } - if (users.length === 1) { - // One result found. Ask user for confirmation. - const name = users.length && users[0].displayName; - conv.ask(`Ready to call ${name}?`, new Suggestions('Yes', `No`)); - conv.contexts.set('calluser_data', 5, { - email: users[0].emailAddress, - name: name - }); - return; - } - - // Multiple matches. Show suggestions of the first few matches. - users = users.slice(0, Math.min(7, users.length)); - - const suggestions = users.map(u => u.displayName); - conv.contexts.set('calluser_getuser', 5); - - conv.ask(`More than one user found with name ${target}. What's the full name?`, new Suggestions(suggestions)); - conv.ask(new Suggestions(suggestions)); + // One result found. Ask user for confirmation. + const name = users.length && users[0].displayName; + conv.ask(`Ready to call ${name}?`, new Suggestions('Yes', `No`)); + conv.contexts.set('calluser_data', 5, { + email: users[0].emailAddress, + name: name + }); }); /** @@ -728,32 +650,20 @@ app.intent('call.user - collect target', async (conv, { target }) => { return; } - let users = await circuit.searchUsers(target); + let users = await getUsers(circuit, conv, target); - if (!users.length) { - conv.ask(`I cannot find any user called ${target}.`); + if (users.length !== 1) { + //Stays in this intent and gets input from user again return; } - if (users.length === 1) { - // One result found. Ask user for confirmation. - const name = users.length && users[0].displayName; - conv.ask(`Ready to call ${name}?`, new Suggestions('Yes', `No`)); - conv.contexts.set('calluser_data', 5, { - email: users[0].emailAddress, - name: name - }); - return; - } - - // Multiple matches. Show suggestions of the first few matches. - users = users.slice(0, Math.min(7, users.length)); - - const suggestions = users.map(u => u.displayName); - conv.contexts.set('calluser_getuser', 5); - - conv.ask(`More than one user or conversation found with name ${target}. What's the full name?`, new Suggestions(suggestions)); - conv.ask(new Suggestions(suggestions)); + // One result found. Ask user for confirmation. + const name = users.length && users[0].displayName; + conv.ask(`Ready to call ${name}?`, new Suggestions('Yes', `No`)); + conv.contexts.set('calluser_data', 5, { + email: users[0].emailAddress, + name: name + }); }); /** @@ -846,6 +756,26 @@ function findWebClient(circuit) { }); } +/** + * Search for a user + */ +async function getUsers(circuit, conv, user) { + let users = await circuit.searchUsers(user); + + if (!users.length) { + //No user found + conv.ask(`I cannot find any user called ${user}. What's the name?`); + } else if (users.length > 1) { + // Multiple users found + users = users.slice(0, Math.min(7, users.length)); + const suggestions = users.map(u => u.displayName); + + conv.ask(`More than one user was found with the name ${user}. What's the full name?`, new Suggestions(suggestions)); + } + + return users; +} + /** * clearSession */ From 04ed982f55011df82b14cdd8e43d97c40fd4e49e Mon Sep 17 00:00:00 2001 From: Chris Date: Sat, 30 Mar 2019 13:15:25 -0400 Subject: [PATCH 6/8] Cleanup/Fixes --- circuitClient.js | 10 ++-- index.js | 120 +++++++++++++++++++++++------------------------ 2 files changed, 65 insertions(+), 65 deletions(-) diff --git a/circuitClient.js b/circuitClient.js index 6954157..0f6e3bb 100644 --- a/circuitClient.js +++ b/circuitClient.js @@ -132,7 +132,8 @@ class CircuitClient { * logon */ logon(accessToken) { - return this.client.logon(accessToken ? { accessToken: accessToken } : undefined).then(user => console.log(`Logged on to Circuit: ${user.displayName}`)); + return this.client.logon(accessToken ? { accessToken: accessToken } : undefined) + .then(user => console.log(`Logged on to Circuit: ${user.displayName}`)); } /** @@ -143,9 +144,10 @@ class CircuitClient { return Promise.resolve(); } const displayName = this.client.loggedOnUser.displayName; - return this.client.logout().then(_ => { - console.log(`Logged out of Circuit: ${displayName}`); - }); + return this.client.logout() + .then(_ => { + console.log(`Logged out of Circuit: ${displayName}`); + }); } ///////////////////////////////////// diff --git a/index.js b/index.js index fcf62be..76438b8 100644 --- a/index.js +++ b/index.js @@ -6,7 +6,7 @@ const CircuitClient = require('./circuitClient'); // Client ID for IMPLICIT app on Circuit. Same ID needs to be defined // in Account Linking of your project at console.actions.google.com -const CLIENT_ID = ''; +const CLIENT_ID = 'd34edad8cda6433bb062f0671f58c232'; // Circuit session timeout const SESSION_TIMEOUT = 5 * 60 * 1000; // 5min session timeout @@ -27,7 +27,7 @@ expressApp.get('/_ah/start', (req, res) => { expressApp.use(bodyParser.json(), app); // Start server -expressApp.listen(process.env.PORT || 8080, () => console.log('Listening at port 8080')); +expressApp.listen(process.env.PORT || 8080); /** * Default Welcome Intent @@ -52,10 +52,10 @@ app.intent('add.participant.to.group', async (conv, { convName, user }) => { return; } - let users = await getUsers(circuit, conv, user); + let users = await searchUsers(circuit, conv, user); let convs = await circuit.searchConversationsByName(convName); - //Save results to context + // Save results to context conv.contexts.set('addparticipantgroup_data', 5, { users: users, convs: convs @@ -67,7 +67,7 @@ app.intent('add.participant.to.group', async (conv, { convName, user }) => { } if (!convs.length) { - //No conversation found + // No conversation found conv.ask(`I cannot find any conversation called ${convName}. What's the name?`); conv.contexts.set('addparticipantgroup_getconv', 5); return; @@ -81,7 +81,7 @@ app.intent('add.participant.to.group', async (conv, { convName, user }) => { return; } - //One result found for user and conversation + // One result found for user and conversation conv.ask(`Ready to add ${users[0].displayName} to ${convs[0].topic}?`, new Suggestions('Yes', 'No')); }); @@ -99,15 +99,15 @@ app.intent('add.participant.to.group - collect.conv', async conv => { let convs = await circuit.searchConversationsByName(convName); if (!convs.length) { - //No conversation found + // No conversation found conv.ask(`I cannot find any conversation called ${convName}. What's the name?`); return; } else if (convs.length > 1) { - //Multiple conversations found + // Multiple conversations found let shortestConvName = [convs[0]]; - //Loop through convs to find shortest conv name - convs.forEach(function(conv, i) { + // Loop through convs to find shortest conv name + convs.forEach(function (conv, i) { if (conv.topic < shortestConvName[0].topic) { shortestConvName[0] = conv; } @@ -116,11 +116,11 @@ app.intent('add.participant.to.group - collect.conv', async conv => { convs = shortestConvName; } - //Save conversation to context because only one found + // Save conversation to context because only one found conv.contexts.set('addparticipantgroup_data', 5, { convs: convs }); conv.contexts.delete('addparticipantgroup_getconv'); - //Users.length is always equal to one at this point + // Users.length is always equal to one at this point conv.ask(`Ready to add ${users[0].displayName} to ${convs[0].topic}?`, new Suggestions('Yes', 'No')); }); @@ -135,19 +135,19 @@ app.intent('add.participant.to.group - collect.user', async conv => { let { convs } = conv.contexts.input['addparticipantgroup_data'].parameters; let user = conv.parameters.user; - let users = await getUsers(circuit, conv, user); + let users = await searchUsers(circuit, conv, user); if (users.length !== 1) { - //Stays in this intent and gets input from user again + // Stays in this intent and gets input from user again return; } - //Save user to context because only one found + // Save user to context because only one found conv.contexts.set('addparticipantgroup_data', 5, { users: users }); conv.contexts.delete('addparticipantgroup_getuser'); if (!convs.length) { - //No conversation found + // No conversation found conv.ask(`Thank you. I did not find the conversation name that you gave me earlier. What is it again?`); conv.contexts.set('addparticipantgroup_getconv', 5); return; @@ -161,7 +161,7 @@ app.intent('add.participant.to.group - collect.user', async conv => { return; } - //One result found for user and conversation + // One result found for user and conversation conv.ask(`Ready to add ${user} to ${convs[0].topic}?`, new Suggestions('Yes', 'No')); }); @@ -192,7 +192,7 @@ app.intent('add.participant.to.group - yes', async conv => { const thisUser = circuit.user; if (convs[0].participants.indexOf(users[0].userId) !== -1) { - //User is already in the conversation + // User is already in the conversation conv.ask(`${users[0].displayName} is already a participant in ${convs[0].topic}. Is there anything else I can do for you?`, new Suggestions('Yes', 'No')); conv.contexts.delete('addparticipantgroup_data'); conv.contexts.set('anything_else', 2); @@ -200,7 +200,7 @@ app.intent('add.participant.to.group - yes', async conv => { } if (convs[0].isModerated && convs[0].moderators.indexOf(thisUser.userId) === -1) { - //Conversation is moderated and thisUser is not a moderator + // Conversation is moderated and user is not a moderator conv.ask(`Sorry, but you are not a moderator in ${convs[0].topic} so ${users[0].displayName} cannot be added. Is there anything else I can do for you?`, new Suggestions('Yes', 'No')); conv.contexts.delete('addparticipantgroup_data'); conv.contexts.set('anything_else', 2); @@ -222,27 +222,27 @@ app.intent('add.participant.to.one', async (conv, { thirdUser, target }) => { return; } - //Save results to context + // Save results to context conv.contexts.set('addparticipantone_data', 5, { thirdUsers: thirdUsers, targetUsers: targetUsers }); - let thirdUsers = await getUsers(circuit, conv, thirdUser); + let thirdUsers = await searchUsers(circuit, conv, thirdUser); if (thirdUsers.length !== 1) { conv.contexts.set('addparticipantone_getuser', 5); return; } - let targetUsers = await getUsers(circuit, conv, target); + let targetUsers = await searchUsers(circuit, conv, target); if (targetUsers.length !== 1) { conv.contexts.set('addparticipantone_getuser', 5); return; } - //One result found for thirdUser and target + // One result found for thirdUser and target conv.ask(`Ready to add ${thirdUsers[0].displayName} to your conversation with ${targetUsers[0].displayName}?`, new Suggestions('Yes', 'No')); }); @@ -257,20 +257,20 @@ app.intent('add.participant.to.one - collect.user', async conv => { let { thirdUsers, targetUsers } = conv.contexts.input['addparticipantone_data'].parameters; let user = conv.parameters.user; - let users = await getUsers(circuit, conv, user); + let users = await searchUsers(circuit, conv, user); if (users.length !== 1) { - //Stays in this intent and gets input from user again + // Stays in this intent and gets input from user again return; } - //One user found beyond this point + // One user found beyond this point let params = conv.contexts.input['addparticipantone_data'].parameters; if (thirdUsers.length !== 1 && !targetUsers.length) { params = conv.contexts.input['addparticipantone_data'].parameters; - //Add thirdUser to context + // Add thirdUser to context params.thirdUsers = [users[0]]; conv.contexts.set('addparticipantone_data', 5, params); @@ -281,7 +281,7 @@ app.intent('add.participant.to.one - collect.user', async conv => { if (thirdUsers.length !== 1 && targetUsers.length > 1) { params = conv.contexts.input['addparticipantone_data'].parameters; - //Add thirdUser to context + // Add thirdUser to context params.thirdUsers = [users[0]]; conv.contexts.set('addparticipantone_data', 5, params); @@ -295,7 +295,7 @@ app.intent('add.participant.to.one - collect.user', async conv => { if (targetUsers.length !== 1) { params = conv.contexts.input['addparticipantone_data'].parameters; - //Add targetUser to context + // Add targetUser to context params.targetUsers = [users[0]]; conv.contexts.set('addparticipantone_data', 5, params); } @@ -330,7 +330,7 @@ app.intent('add.participant.to.one - yes', async conv => { const conversation = await circuit.getDirectConversationWithUser(targetUsers[0].userId); if (!conversation) { - //No direct conversation found + // No direct conversation found conv.ask(`You are not in a direct conversation with ${targetUsers[0].displayName}. Is there anything else I can do for you?`, new Suggestions('Yes', 'No')); conv.contexts.delete('addparticipantone_data'); conv.contexts.set('anything_else', 2); @@ -338,7 +338,7 @@ app.intent('add.participant.to.one - yes', async conv => { } if (thirdUsers[0].userId === targetUsers[0].userId) { - //thirdUser and targetUser is the same user + // thirdUser and targetUser is the same user conv.ask(`I cannot add ${thirdUsers[0].displayName} to his own conversation. Is there anything else I can do for you?`, new Suggestions('Yes', 'No')); conv.contexts.delete('addparticipantone_data'); conv.contexts.set('anything_else', 2); @@ -361,10 +361,10 @@ app.intent('remove.participant', async (conv, { user, convName }) => { return; } - let users = await getUsers(circuit, conv, user); + let users = await searchUsers(circuit, conv, user); let convs = await circuit.searchConversationsByName(convName); - //Save results to context + // Save results to context conv.contexts.set('removeparticipant_data', 5, { users: users, convs: convs @@ -376,7 +376,7 @@ app.intent('remove.participant', async (conv, { user, convName }) => { } if (!convs.length) { - //No conversation found + // No conversation found conv.ask(`I cannot find any conversation called ${convName}. What's the name?`); conv.contexts.set('removeparticipant_getconv', 5); return; @@ -390,7 +390,7 @@ app.intent('remove.participant', async (conv, { user, convName }) => { return; } - //One result found for user and conversation + // One result found for user and conversation conv.ask(`Ready to remove ${users[0].displayName} from ${convs[0].topic}?`, new Suggestions('Yes', 'No')); }); @@ -408,15 +408,15 @@ app.intent('remove.participant - collect.conv', async conv => { let convs = await circuit.searchConversationsByName(convName); if (!convs.length) { - //No conversation found + // No conversation found conv.ask(`I cannot find any conversation called ${convName}. What's the name?`); return; } else if (convs.length > 1) { - //Multiple conversations found + // Multiple conversations found let shortestConvName = [convs[0]]; - //Loop through convs to find shortest conv name - convs.forEach(function(conv, i) { + // Loop through convs to find shortest conv name + convs.forEach(function (conv, i) { if (conv.topic < shortestConvName[0].topic) { shortestConvName[0] = conv; } @@ -425,11 +425,11 @@ app.intent('remove.participant - collect.conv', async conv => { convs = shortestConvName; } - //Save conversation to context because only one found + // Save conversation to context because only one found conv.contexts.set('removeparticipant_data', 5, { convs: convs }); conv.contexts.delete('removeparticipant_getconv'); - //Users.length is always equal to one at this point + // Users.length is always equal to one at this point conv.ask(`Ready to remove ${users[0].displayName} from ${convs[0].topic}?`, new Suggestions('Yes', 'No')); }); @@ -444,19 +444,19 @@ app.intent('remove.participant - collect.user', async conv => { let { convs } = conv.contexts.input['removeparticipant_data'].parameters; let user = conv.parameters.user; - let users = await getUsers(circuit, conv, user); + let users = await searchUsers(circuit, conv, user); if (users.length !== 1) { - //Stays in this intent and gets input from user again + // Stays in this intent and gets input from user again return; } - //Save user to context because only one found + // Save user to context because only one found conv.contexts.set('removeparticipant_data', 5, { users: users }); conv.contexts.delete('removeparticipant_getuser'); if (!convs.length) { - //No conversation found + // No conversation found conv.ask(`Thank you. I did not find the conversation name that you gave me earlier. What is it again?`); conv.contexts.set('removeparticipant_getconv', 5); return; @@ -470,7 +470,7 @@ app.intent('remove.participant - collect.user', async conv => { return; } - //One result found for user and conversation + // One result found for user and conversation conv.ask(`Ready to remove ${user} from ${convs[0].topic}?`, new Suggestions('Yes', 'No')); }); @@ -501,7 +501,7 @@ app.intent('remove.participant - yes', async conv => { const thisUser = circuit.user; if (convs[0].participants.indexOf(users[0].userId) === -1) { - //User is already in the conversation + // User is already in the conversation conv.ask(`${users[0].displayName} is not a participant in ${convs[0].topic}. Is there anything else I can do for you?`, new Suggestions('Yes', 'No')); conv.contexts.delete('removeparticipant_data'); conv.contexts.set('anything_else', 2); @@ -509,7 +509,7 @@ app.intent('remove.participant - yes', async conv => { } if (convs[0].isModerated && convs[0].moderators.indexOf(thisUser.userId) === -1) { - //Conversation is moderated and thisUser is not a moderator + // Conversation is moderated and thisUser is not a moderator conv.ask(`Sorry, but you are not a moderator in ${convs[0].topic} so ${users[0].displayName} cannot be removed. Is there anything else I can do for you?`, new Suggestions('Yes', 'No')); conv.contexts.delete('removeparticipant_data'); conv.contexts.set('anything_else', 2); @@ -556,7 +556,6 @@ app.intent('send.message', async (conv, { target, message }) => { // Multiple matches. Show suggestions of the first few matches. users = users.slice(0, Math.min(7, users.length)); - //convs = convs.slice(0, Math.min(7, convs.length)); const suggestions = users.map(u => u.displayName); conv.contexts.set('sendmessage_getconv', 5); @@ -602,7 +601,7 @@ app.intent('send.message - yes', async conv => { await circuit.addTextItem(convId, message); conv.contexts.delete('sendmessage_data'); conv.ask('Message sent. Is there anything else I can do for you?'); - conv.ask(new Suggestions("No, that's all", 'Yes')); + conv.ask(new Suggestions('No, that\'s all', 'Yes')); conv.contexts.set('anything_else', 2); }); @@ -612,7 +611,7 @@ app.intent('send.message - yes', async conv => { app.intent('send.message - no', async conv => { conv.contexts.delete('sendmessage_data'); conv.ask('Message not sent. Is there anything else I can do for you?'); - conv.ask(new Suggestions("No, that's all", 'Yes')); + conv.ask(new Suggestions('No, that\'s all', 'Yes')); conv.contexts.set('anything_else', 2); }); @@ -625,7 +624,7 @@ app.intent('call.user', async (conv, { target }) => { return; } - let users = await getUsers(circuit, conv, target); + let users = await searchUsers(circuit, conv, target); if (users.length !== 1) { conv.contexts.set('calluser_getuser', 5); @@ -650,10 +649,10 @@ app.intent('call.user - collect target', async (conv, { target }) => { return; } - let users = await getUsers(circuit, conv, target); + let users = await searchUsers(circuit, conv, target); if (users.length !== 1) { - //Stays in this intent and gets input from user again + // Stays in this intent and gets input from user again return; } @@ -689,7 +688,7 @@ app.intent('call.user - yes', async conv => { app.intent('call.user - no', async conv => { conv.contexts.delete('calluser_data'); conv.ask('Is there anything else I can do for you?'); - conv.ask(new Suggestions("No, that's all", 'Yes')); + conv.ask(new Suggestions('No, that\'s all', 'Yes')); conv.contexts.set('anything_else', 2); }); @@ -732,13 +731,12 @@ async function getCircuit(conv) { */ function createSession(user) { const circuit = new CircuitClient({ client_id: CLIENT_ID }); - return circuit - .logon(user.access.token) + return circuit.logon(user.access.token) .then(() => { const session = { circuit: circuit, timer: setTimeout(clearSession.bind(null, user.storage), SESSION_TIMEOUT) - }; + } sessions[user.storage] = session; return session; }) @@ -759,11 +757,11 @@ function findWebClient(circuit) { /** * Search for a user */ -async function getUsers(circuit, conv, user) { - let users = await circuit.searchUsers(user); +async function searchUsers(circuit, conv, query) { + let users = await circuit.searchUsers(query); if (!users.length) { - //No user found + // No user found conv.ask(`I cannot find any user called ${user}. What's the name?`); } else if (users.length > 1) { // Multiple users found From 9634695d99c6198f1f87533c0f7e8ff2656c0d40 Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 5 Apr 2019 11:58:15 -0400 Subject: [PATCH 7/8] Bug fix & code review changes --- circuitClient.js | 20 +++----- index.js | 129 ++++++++++++++++++++++------------------------- 2 files changed, 67 insertions(+), 82 deletions(-) diff --git a/circuitClient.js b/circuitClient.js index 0f6e3bb..8409594 100644 --- a/circuitClient.js +++ b/circuitClient.js @@ -18,7 +18,7 @@ class CircuitClient { })[0]; } return c; - }; + } // Function bindings this.addParticipant = this.client.addParticipant; @@ -33,9 +33,7 @@ class CircuitClient { // Properties Object.defineProperty(this, 'user', { - get: _ => { - return this.client.loggedOnUser; - } + get: _ => { return this.client.loggedOnUser; } }); } @@ -43,7 +41,7 @@ class CircuitClient { /// Public functions ///////////////////////////////////// - async searchUsers(query) { + async searchUsers (query) { const self = this; return new Promise(async resolve => { let searchId; @@ -119,19 +117,17 @@ class CircuitClient { self.client.addEventListener('basicSearchResults', searchResultHandler); self.client.addEventListener('searchStatus', searchStatusHandler); - searchId = await self.client.startBasicSearch([ - { - scope: Circuit.Enums.SearchScope.CONVERSATIONS, - searchTerm: query - } - ]); + searchId = await self.client.startBasicSearch([{ + scope: Circuit.Enums.SearchScope.CONVERSATIONS, + searchTerm: query + }]); }); } /** * logon */ - logon(accessToken) { + logon (accessToken) { return this.client.logon(accessToken ? { accessToken: accessToken } : undefined) .then(user => console.log(`Logged on to Circuit: ${user.displayName}`)); } diff --git a/index.js b/index.js index 76438b8..4024e17 100644 --- a/index.js +++ b/index.js @@ -52,7 +52,7 @@ app.intent('add.participant.to.group', async (conv, { convName, user }) => { return; } - let users = await searchUsers(circuit, conv, user); + const users = await searchUsers(circuit, conv, user); let convs = await circuit.searchConversationsByName(convName); // Save results to context @@ -75,7 +75,6 @@ app.intent('add.participant.to.group', async (conv, { convName, user }) => { // Multiple conversations found. convs = convs.slice(0, Math.min(7, convs.length)); const suggestions = convs.map(c => c.topic); - conv.ask(`More than one conversation was found with the name ${convName}. What's the full name?`, new Suggestions(suggestions)); conv.contexts.set('addparticipantgroup_getconv', 5); return; @@ -95,7 +94,7 @@ app.intent('add.participant.to.group - collect.conv', async conv => { } const { users } = conv.contexts.input['addparticipantgroup_data'].parameters; - let convName = conv.parameters.convName; + const convName = conv.parameters.convName; let convs = await circuit.searchConversationsByName(convName); if (!convs.length) { @@ -104,18 +103,16 @@ app.intent('add.participant.to.group - collect.conv', async conv => { return; } else if (convs.length > 1) { // Multiple conversations found - let shortestConvName = [convs[0]]; + let shortestConv = convs[0]; // Loop through convs to find shortest conv name - convs.forEach(function (conv, i) { - if (conv.topic < shortestConvName[0].topic) { - shortestConvName[0] = conv; + convs.forEach(conv => { + if (conv.topic < shortestConv.topic) { + shortestConv = conv; } }); - - convs = shortestConvName; + convs = [shortestConv]; } - // Save conversation to context because only one found conv.contexts.set('addparticipantgroup_data', 5, { convs: convs }); conv.contexts.delete('addparticipantgroup_getconv'); @@ -134,11 +131,11 @@ app.intent('add.participant.to.group - collect.user', async conv => { } let { convs } = conv.contexts.input['addparticipantgroup_data'].parameters; - let user = conv.parameters.user; - let users = await searchUsers(circuit, conv, user); + const user = conv.parameters.user; + const users = await searchUsers(circuit, conv, user); + // Stays in this intent and gets input from user again if (users.length !== 1) { - // Stays in this intent and gets input from user again return; } @@ -155,12 +152,10 @@ app.intent('add.participant.to.group - collect.user', async conv => { // Multiple conversations found. convs = convs.slice(0, Math.min(7, convs.length)); const suggestions = convs.map(c => c.topic); - conv.ask(`Thank you. I found more than one result for the conversation name you gave me earlier. What's the full name?`, new Suggestions(suggestions)); conv.contexts.set('addparticipantgroup_getconv', 5); return; } - // One result found for user and conversation conv.ask(`Ready to add ${user} to ${convs[0].topic}?`, new Suggestions('Yes', 'No')); }); @@ -191,7 +186,7 @@ app.intent('add.participant.to.group - yes', async conv => { const { users, convs } = conv.contexts.input['addparticipantgroup_data'].parameters; const thisUser = circuit.user; - if (convs[0].participants.indexOf(users[0].userId) !== -1) { + if (convs[0].participants.some(userId => userId === users[0].userId)) { // User is already in the conversation conv.ask(`${users[0].displayName} is already a participant in ${convs[0].topic}. Is there anything else I can do for you?`, new Suggestions('Yes', 'No')); conv.contexts.delete('addparticipantgroup_data'); @@ -199,7 +194,7 @@ app.intent('add.participant.to.group - yes', async conv => { return; } - if (convs[0].isModerated && convs[0].moderators.indexOf(thisUser.userId) === -1) { + if (convs[0].isModerated && !convs[0].moderators.some(userId => userId === thisUser.userId)) { // Conversation is moderated and user is not a moderator conv.ask(`Sorry, but you are not a moderator in ${convs[0].topic} so ${users[0].displayName} cannot be added. Is there anything else I can do for you?`, new Suggestions('Yes', 'No')); conv.contexts.delete('addparticipantgroup_data'); @@ -222,20 +217,24 @@ app.intent('add.participant.to.one', async (conv, { thirdUser, target }) => { return; } - // Save results to context - conv.contexts.set('addparticipantone_data', 5, { - thirdUsers: thirdUsers, - targetUsers: targetUsers - }); + const thirdUsers = await searchUsers(circuit, conv, thirdUser); + const params = {}; + params.thirdUsers = thirdUsers; + params.targetQuery = conv.parameters.target; - let thirdUsers = await searchUsers(circuit, conv, thirdUser); + // Save results to context + conv.contexts.set('addparticipantone_data', 5, params); if (thirdUsers.length !== 1) { conv.contexts.set('addparticipantone_getuser', 5); return; } - let targetUsers = await searchUsers(circuit, conv, target); + const targetUsers = await searchUsers(circuit, conv, target); + params.targetUsers = targetUsers; + + // Save results to context + conv.contexts.set('addparticipantone_data', 5, params); if (targetUsers.length !== 1) { conv.contexts.set('addparticipantone_getuser', 5); @@ -255,47 +254,42 @@ app.intent('add.participant.to.one - collect.user', async conv => { return; } - let { thirdUsers, targetUsers } = conv.contexts.input['addparticipantone_data'].parameters; - let user = conv.parameters.user; - let users = await searchUsers(circuit, conv, user); + const { thirdUsers, targetQuery } = conv.contexts.input['addparticipantone_data'].parameters; + let { targetUsers } = conv.contexts.input['addparticipantone_data'].parameters; + const user = conv.parameters.user; + const users = await searchUsers(circuit, conv, user); + // Stays in this intent and gets input from user again if (users.length !== 1) { - // Stays in this intent and gets input from user again return; } // One user found beyond this point - let params = conv.contexts.input['addparticipantone_data'].parameters; - - if (thirdUsers.length !== 1 && !targetUsers.length) { - params = conv.contexts.input['addparticipantone_data'].parameters; + const params = conv.contexts.input['addparticipantone_data'].parameters; + if (thirdUsers.length !== 1) { // Add thirdUser to context params.thirdUsers = [users[0]]; conv.contexts.set('addparticipantone_data', 5, params); - - conv.ask(`Thank you. I couldn't find the user whose conversation you wanted me to add ${users[0].displayName} to. What's the name again?`); - return; + conv.ask('Thank you.'); } - if (thirdUsers.length !== 1 && targetUsers.length > 1) { - params = conv.contexts.input['addparticipantone_data'].parameters; + if (!targetUsers) { + // Searches for target user + targetUsers = await searchUsers(circuit, conv, targetQuery); - // Add thirdUser to context - params.thirdUsers = [users[0]]; - conv.contexts.set('addparticipantone_data', 5, params); + if (targetUsers.length !== 1) { + // Add the target user to context + params.targetUsers = targetUsers; + conv.contexts.set('addparticipantone_data', 5, params); - let tempUsers = targetUsers.slice(0, Math.min(7, targetUsers.length)); - const suggestions = tempUsers.map(u => u.displayName); - - conv.ask(`Thank you. I found more than one user whose conversation you wanted me to add ${users[0].displayName} to. What's the full name?`, new Suggestions(suggestions)); - return; + // Stays in this intent and gets input from user again + return; + } } if (targetUsers.length !== 1) { - params = conv.contexts.input['addparticipantone_data'].parameters; - - // Add targetUser to context + // Add the target user to context params.targetUsers = [users[0]]; conv.contexts.set('addparticipantone_data', 5, params); } @@ -361,7 +355,7 @@ app.intent('remove.participant', async (conv, { user, convName }) => { return; } - let users = await searchUsers(circuit, conv, user); + const users = await searchUsers(circuit, conv, user); let convs = await circuit.searchConversationsByName(convName); // Save results to context @@ -384,7 +378,6 @@ app.intent('remove.participant', async (conv, { user, convName }) => { // Multiple conversations found. convs = convs.slice(0, Math.min(7, convs.length)); const suggestions = convs.map(c => c.topic); - conv.ask(`More than one conversation was found with the name ${convName}. What's the full name?`, new Suggestions(suggestions)); conv.contexts.set('removeparticipant_getconv', 5); return; @@ -404,7 +397,7 @@ app.intent('remove.participant - collect.conv', async conv => { } const { users } = conv.contexts.input['removeparticipant_data'].parameters; - let convName = conv.parameters.convName; + const convName = conv.parameters.convName; let convs = await circuit.searchConversationsByName(convName); if (!convs.length) { @@ -413,18 +406,16 @@ app.intent('remove.participant - collect.conv', async conv => { return; } else if (convs.length > 1) { // Multiple conversations found - let shortestConvName = [convs[0]]; + let shortestConv = convs[0]; // Loop through convs to find shortest conv name - convs.forEach(function (conv, i) { - if (conv.topic < shortestConvName[0].topic) { - shortestConvName[0] = conv; + convs.forEach(conv => { + if (conv.topic < shortestConv.topic) { + shortestConv = conv; } }); - - convs = shortestConvName; + convs = [shortestConv]; } - // Save conversation to context because only one found conv.contexts.set('removeparticipant_data', 5, { convs: convs }); conv.contexts.delete('removeparticipant_getconv'); @@ -443,11 +434,11 @@ app.intent('remove.participant - collect.user', async conv => { } let { convs } = conv.contexts.input['removeparticipant_data'].parameters; - let user = conv.parameters.user; - let users = await searchUsers(circuit, conv, user); + const user = conv.parameters.user; + const users = await searchUsers(circuit, conv, user); + // Stays in this intent and gets input from user again if (users.length !== 1) { - // Stays in this intent and gets input from user again return; } @@ -464,7 +455,6 @@ app.intent('remove.participant - collect.user', async conv => { // Multiple conversations found. convs = convs.slice(0, Math.min(7, convs.length)); const suggestions = convs.map(c => c.topic); - conv.ask(`Thank you. I found more than one result for the conversation name you gave me earlier. What's the full name?`, new Suggestions(suggestions)); conv.contexts.set('removeparticipant_getconv', 5); return; @@ -500,15 +490,15 @@ app.intent('remove.participant - yes', async conv => { const { users, convs } = conv.contexts.input['removeparticipant_data'].parameters; const thisUser = circuit.user; - if (convs[0].participants.indexOf(users[0].userId) === -1) { - // User is already in the conversation + if (!convs[0].participants.some(userId => userId === users[0].userId)) { + // User is not in the conversation conv.ask(`${users[0].displayName} is not a participant in ${convs[0].topic}. Is there anything else I can do for you?`, new Suggestions('Yes', 'No')); conv.contexts.delete('removeparticipant_data'); conv.contexts.set('anything_else', 2); return; } - if (convs[0].isModerated && convs[0].moderators.indexOf(thisUser.userId) === -1) { + if (convs[0].isModerated && !convs[0].moderators.some(userId => userId === thisUser.userId)) { // Conversation is moderated and thisUser is not a moderator conv.ask(`Sorry, but you are not a moderator in ${convs[0].topic} so ${users[0].displayName} cannot be removed. Is there anything else I can do for you?`, new Suggestions('Yes', 'No')); conv.contexts.delete('removeparticipant_data'); @@ -516,7 +506,7 @@ app.intent('remove.participant - yes', async conv => { return; } - await circuit.removeParticipant(convs[0].convId, users[0].userId, true); + await circuit.removeParticipant(convs[0].convId, users[0].userId); conv.ask(`${users[0].displayName} was removed from ${convs[0].topic}. Is there anything else I can do for you?`, new Suggestions('Yes', 'No')); conv.contexts.delete('removeparticipant_data'); conv.contexts.set('anything_else', 2); @@ -651,8 +641,8 @@ app.intent('call.user - collect target', async (conv, { target }) => { let users = await searchUsers(circuit, conv, target); + // Stays in this intent and gets input from user again if (users.length !== 1) { - // Stays in this intent and gets input from user again return; } @@ -695,7 +685,6 @@ app.intent('call.user - no', async conv => { /** * Common intents */ - app.intent('anything.else - yes', async conv => { conv.followup('Welcome'); }); @@ -762,13 +751,13 @@ async function searchUsers(circuit, conv, query) { if (!users.length) { // No user found - conv.ask(`I cannot find any user called ${user}. What's the name?`); + conv.ask(`I cannot find any user called ${query}. What's the name?`); } else if (users.length > 1) { // Multiple users found users = users.slice(0, Math.min(7, users.length)); const suggestions = users.map(u => u.displayName); - conv.ask(`More than one user was found with the name ${user}. What's the full name?`, new Suggestions(suggestions)); + conv.ask(`More than one user was found with the name ${query}. What's the full name?`, new Suggestions(suggestions)); } return users; From 53fad9c9122e14ce85ced67a2239e778fcb3a73f Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 5 Apr 2019 12:34:11 -0400 Subject: [PATCH 8/8] Code review changes --- index.js | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/index.js b/index.js index 4024e17..d8d4ccc 100644 --- a/index.js +++ b/index.js @@ -66,8 +66,8 @@ app.intent('add.participant.to.group', async (conv, { convName, user }) => { return; } + // No conversation found if (!convs.length) { - // No conversation found conv.ask(`I cannot find any conversation called ${convName}. What's the name?`); conv.contexts.set('addparticipantgroup_getconv', 5); return; @@ -97,8 +97,8 @@ app.intent('add.participant.to.group - collect.conv', async conv => { const convName = conv.parameters.convName; let convs = await circuit.searchConversationsByName(convName); + // No conversation found if (!convs.length) { - // No conversation found conv.ask(`I cannot find any conversation called ${convName}. What's the name?`); return; } else if (convs.length > 1) { @@ -143,8 +143,8 @@ app.intent('add.participant.to.group - collect.user', async conv => { conv.contexts.set('addparticipantgroup_data', 5, { users: users }); conv.contexts.delete('addparticipantgroup_getuser'); + // No conversation found if (!convs.length) { - // No conversation found conv.ask(`Thank you. I did not find the conversation name that you gave me earlier. What is it again?`); conv.contexts.set('addparticipantgroup_getconv', 5); return; @@ -186,16 +186,16 @@ app.intent('add.participant.to.group - yes', async conv => { const { users, convs } = conv.contexts.input['addparticipantgroup_data'].parameters; const thisUser = circuit.user; + // User is already in the conversation if (convs[0].participants.some(userId => userId === users[0].userId)) { - // User is already in the conversation conv.ask(`${users[0].displayName} is already a participant in ${convs[0].topic}. Is there anything else I can do for you?`, new Suggestions('Yes', 'No')); conv.contexts.delete('addparticipantgroup_data'); conv.contexts.set('anything_else', 2); return; } + // Conversation is moderated and user is not a moderator if (convs[0].isModerated && !convs[0].moderators.some(userId => userId === thisUser.userId)) { - // Conversation is moderated and user is not a moderator conv.ask(`Sorry, but you are not a moderator in ${convs[0].topic} so ${users[0].displayName} cannot be added. Is there anything else I can do for you?`, new Suggestions('Yes', 'No')); conv.contexts.delete('addparticipantgroup_data'); conv.contexts.set('anything_else', 2); @@ -218,9 +218,10 @@ app.intent('add.participant.to.one', async (conv, { thirdUser, target }) => { } const thirdUsers = await searchUsers(circuit, conv, thirdUser); - const params = {}; - params.thirdUsers = thirdUsers; - params.targetQuery = conv.parameters.target; + const params = { + thirdUsers: thirdUsers, + targetQuery: conv.parameters.target + } // Save results to context conv.contexts.set('addparticipantone_data', 5, params); @@ -267,19 +268,19 @@ app.intent('add.participant.to.one - collect.user', async conv => { // One user found beyond this point const params = conv.contexts.input['addparticipantone_data'].parameters; + // Add thirdUser to context if (thirdUsers.length !== 1) { - // Add thirdUser to context params.thirdUsers = [users[0]]; conv.contexts.set('addparticipantone_data', 5, params); conv.ask('Thank you.'); } + // Searches for target user if (!targetUsers) { - // Searches for target user targetUsers = await searchUsers(circuit, conv, targetQuery); + // Add the target user to context if (targetUsers.length !== 1) { - // Add the target user to context params.targetUsers = targetUsers; conv.contexts.set('addparticipantone_data', 5, params); @@ -288,8 +289,8 @@ app.intent('add.participant.to.one - collect.user', async conv => { } } + // Add the target user to context if (targetUsers.length !== 1) { - // Add the target user to context params.targetUsers = [users[0]]; conv.contexts.set('addparticipantone_data', 5, params); } @@ -323,16 +324,16 @@ app.intent('add.participant.to.one - yes', async conv => { const { thirdUsers, targetUsers } = conv.contexts.input['addparticipantone_data'].parameters; const conversation = await circuit.getDirectConversationWithUser(targetUsers[0].userId); + // No direct conversation found if (!conversation) { - // No direct conversation found conv.ask(`You are not in a direct conversation with ${targetUsers[0].displayName}. Is there anything else I can do for you?`, new Suggestions('Yes', 'No')); conv.contexts.delete('addparticipantone_data'); conv.contexts.set('anything_else', 2); return; } + // thirdUser and targetUser are the same user if (thirdUsers[0].userId === targetUsers[0].userId) { - // thirdUser and targetUser is the same user conv.ask(`I cannot add ${thirdUsers[0].displayName} to his own conversation. Is there anything else I can do for you?`, new Suggestions('Yes', 'No')); conv.contexts.delete('addparticipantone_data'); conv.contexts.set('anything_else', 2); @@ -369,8 +370,8 @@ app.intent('remove.participant', async (conv, { user, convName }) => { return; } + // No conversation found if (!convs.length) { - // No conversation found conv.ask(`I cannot find any conversation called ${convName}. What's the name?`); conv.contexts.set('removeparticipant_getconv', 5); return; @@ -400,8 +401,8 @@ app.intent('remove.participant - collect.conv', async conv => { const convName = conv.parameters.convName; let convs = await circuit.searchConversationsByName(convName); + // No conversation found if (!convs.length) { - // No conversation found conv.ask(`I cannot find any conversation called ${convName}. What's the name?`); return; } else if (convs.length > 1) { @@ -446,8 +447,8 @@ app.intent('remove.participant - collect.user', async conv => { conv.contexts.set('removeparticipant_data', 5, { users: users }); conv.contexts.delete('removeparticipant_getuser'); + // No conversation found if (!convs.length) { - // No conversation found conv.ask(`Thank you. I did not find the conversation name that you gave me earlier. What is it again?`); conv.contexts.set('removeparticipant_getconv', 5); return; @@ -490,16 +491,16 @@ app.intent('remove.participant - yes', async conv => { const { users, convs } = conv.contexts.input['removeparticipant_data'].parameters; const thisUser = circuit.user; + // User is not in the conversation if (!convs[0].participants.some(userId => userId === users[0].userId)) { - // User is not in the conversation conv.ask(`${users[0].displayName} is not a participant in ${convs[0].topic}. Is there anything else I can do for you?`, new Suggestions('Yes', 'No')); conv.contexts.delete('removeparticipant_data'); conv.contexts.set('anything_else', 2); return; } + // Conversation is moderated and thisUser is not a moderator if (convs[0].isModerated && !convs[0].moderators.some(userId => userId === thisUser.userId)) { - // Conversation is moderated and thisUser is not a moderator conv.ask(`Sorry, but you are not a moderator in ${convs[0].topic} so ${users[0].displayName} cannot be removed. Is there anything else I can do for you?`, new Suggestions('Yes', 'No')); conv.contexts.delete('removeparticipant_data'); conv.contexts.set('anything_else', 2);