Skip to content

Commit

Permalink
#7 #8 refactor end dialog scenario, name, and convert to good name.
Browse files Browse the repository at this point in the history
  • Loading branch information
kosalaperera committed Jun 10, 2017
1 parent 566244f commit 8e44729
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 62 deletions.
5 changes: 4 additions & 1 deletion bot/modules/dialogs/assigned.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ const lib = new builder.Library('assigned');

lib.dialog('/', [
(session) => {

const {
name
} = session.message.user;
const goodname = name.split(' ').slice(0, -1).join(' ');

session.endDialog(`Patience ${name}... I am working on it. So for now, just go figure :P`);
session.send(`Patience ${goodname}... I am working on it. So for now, just go figure :P`)
.endDialog();
}
])
.triggerAction({
Expand Down
47 changes: 18 additions & 29 deletions bot/modules/dialogs/greet.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,32 @@ const lib = new builder.Library('greet');

lib.dialog('/', [
(session, args, next) => {

if (session.userData.profile) {
session.beginDialog('/hi');
} else {
session.beginDialog('/ano');
const {
goodname,
emailAddress
} = session.userData.profile;

return session.send(`Hay ${goodname}... looks like you are already signed in as **${emailAddress}** :)`)
.send(`Type **reset** if that's not your email and we can start over.`)
.send(`Or just type **help** to figure out what's next :)`)
.endDialog();
}

const {
name
} = session.message.user;
const goodname = name.split(' ').slice(0, -1).join(' ');

session.send(`Hay ${goodname}... looks like you haven't signed in yet. Say **sign in as _your domain username_** so we can proceed :)`)
.endDialog();
}
])
.triggerAction({
matches: ['/greet']
});

lib.dialog('/hi', [
(session, args, next) => {
const {
name
} = session.message.user;
const email = session.userData.profile.emailAddress;

session.send(`Hay ${name}... looks like you are already signed in as **${email}** :)`)
.send(`Type **reset** if that's not your email and we can start all over.`)
.send(`Or just type **help** to figure out what's next :)`)
.endDialog();
}
]);

lib.dialog('/ano', [
(session, args, next) => {
const {
name
} = session.message.user;

session.send(`Hay ${name}...`)
.send(`Looks like you haven't signed in yet. Say **sign in as _your domain username_** OR **_email address_** so we can proceed :)`)
.endDialog();
}
]);

module.exports = exports = {
createNew: () => {
return lib.clone();
Expand Down
2 changes: 1 addition & 1 deletion bot/modules/dialogs/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ lib.dialog('/', [
},

(session, args, next) => {
session.send(`* Say **sign in as _your domain username_** OR **_email address_** so we can proceed with JIRA authentication.\n* Type **reset** and I will lose all the sweet memories we had together and we can start all over ;)`)
session.send(`* Say **sign in as _your domain username_** so we can proceed with JIRA authentication.\n* Type **reset** and I will lose all the sweet memories we had together and we can start all over ;)`)
.send(`Now, if you are wondering how to report time, it's like this... You just type what you have been working, mention the **JIRA Task, Day, and the Time you spent** but the order really doesnt matter. I will tell JIRA to note it down :)`)
.send(`For example... \n* _**CIN-27** **5/23** I just played with JIRA Journal Bot for **1h 30m**_ OR \n* _**CIN-27** Playing around the JIRA Journal Bot source **yesterday 4.5h**_ OR \n* _**Today** Troubleshooting my shame code for about **6h CIN-27**_`)
.send(`Just say **nevermind** to start over at any time.`)
Expand Down
5 changes: 4 additions & 1 deletion bot/modules/dialogs/recent.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ const lib = new builder.Library('recent');

lib.dialog('/', [
(session) => {

const {
name
} = session.message.user;
const goodname = name.split(' ').slice(0, -1).join(' ');

session.endDialog(`Patience ${name}... I am working on it. So for now, just go figure :P`);
session.send(`Patience ${goodname}... I am working on it. So for now, just go figure :P`)
.endDialog();
}
])
.triggerAction({
Expand Down
52 changes: 22 additions & 30 deletions bot/modules/dialogs/worklog.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,14 @@ lib.dialog('/task', [

(session, results, next) => {

const usernameOrEmail = session.userData.profile.emailAddress;
const task = results.response;
const {
emailAddress
} = session.userData.profile;

session.sendTyping();

auth.authorize(usernameOrEmail, task)
auth.authorize(emailAddress, task)
.then((response) => {
session.endDialogWithResult({
response: {
Expand All @@ -132,25 +134,19 @@ lib.dialog('/task', [

switch (statusCode) {
case 401:
session.send(`Oops! Looks like you don't have access to that project. Talk to IT Services.`)
.endDialogWithResult({
resumed: builder.ResumeReason.notCompleted
});
session.send(`Oops! Looks like you don't have access to that project. Talk to IT Services.`);
break;
case 404:
session.send(`Oops! Cannot find that task. May be it doesn't exists or not created yet.`)
.endDialogWithResult({
resumed: builder.ResumeReason.notCompleted
});
session.send(`Oops! Cannot find that task. May be it doesn't exists or not created yet.`);
break;
default:
session.send(`Oops! Something went wrong. Shame on us! Try a bit later.`)
.endDialogWithResult({
resumed: builder.ResumeReason.notCompleted
});

session.send(`Oops! Something went wrong. Shame on us! Try a bit later.`);
break;
}

session.endDialogWithResult({
resumed: builder.ResumeReason.notCompleted
});
});
}
])
Expand Down Expand Up @@ -230,39 +226,35 @@ lib.dialog('/complete', [

jira.addWorklog(project, task, worklog)
.then((response) => {
session.endDialog('(y)');
session.send('(y)')
.endDialog();
})
.catch((error) => {
const {
statusCode
} = error;

const {
name
} = session.message.user;
goodname
} = session.userData.profile;

switch (statusCode) {
case 401:
session.send(`Your JIRA credentials no longer working, ${name}. Just talk to IT Services about it.`)
.endDialogWithResult({
resumed: builder.ResumeReason.notCompleted
});
session.send(`Your JIRA credentials no longer working, ${goodname}. Just talk to IT Services about it.`);
break;

case 404:
session.send(`Oops! ${task} task doesn't exists or you don't have permission, ${name}.`)
.endDialogWithResult({
resumed: builder.ResumeReason.notCompleted
});
session.send(`Oops! ${task} task doesn't exists or you don't have permission, ${goodname}.`);
break;

default:
session.send(`Oops! Something went wrong. Shame on us (facepalm). Let's try again in few mins.`)
.endDialogWithResult({
resumed: builder.ResumeReason.notCompleted
});
session.send(`Oops! Something went wrong. Shame on us (facepalm). Let's try again in few mins.`);
break;
}

session.endDialogWithResult({
resumed: builder.ResumeReason.notCompleted
});
});
}
]);
Expand Down

0 comments on commit 8e44729

Please sign in to comment.