Skip to content

Commit

Permalink
Added error handling code for bad UserIDs in the source sheet
Browse files Browse the repository at this point in the history
  • Loading branch information
Vishal Parpia committed Apr 23, 2020
1 parent dd3d0ca commit adbf495
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const readingStrings = [

//Welcome to @mercury
const welcomeStrings = [
"Hi there! I'm @mercury and I'm a temperature taking bot. My job is to make sure my humans don't overheat 🤒"
"Hi there! I'm @mercury and I'm a temperature taking bot. My job is to make sure my humans don't overheat 🤒. Just slack me your temperature and I'll remember it. If you forget to give me your morning temperature you can send me your reading suffixed with `AM` even in the afternoon."
];

// If modifying these scopes, delete token.json.
Expand Down Expand Up @@ -154,11 +154,14 @@ function writeTemp(auth, params) {

function sendMessage(u, m) {
(async () => {
console.log(`Sending message to ${u}`);
// Post a message to the channel, and await the result.
// Find more arguments and details of the response: https://api.slack.com/methods/chat.postMessage
const result = await slack.chat.postMessage({
text: m,
channel: u,
}).catch(e => {
console.log(e);
});

// The result contains an identifier for the message, `ts`.
Expand Down Expand Up @@ -255,7 +258,7 @@ exports.slackAttack = (req, res) => {
} else {
userTempC = convertResponse(e.user, e.text);
if (userTempC > 50) {
sendMessage(e.user, "Wow that's really hot 🔥! Are you sure that's in *degrees celcius*?");
sendMessage(e.user, "Wow that's really hot 🔥! Are you sure that's right?");
} else if (userTempC >= 35 && userTempC < 37.5) {
authorize(JSON.parse(process.env.gsuiteCreds), writeTemp, {u: e.user, t: userTempC, a: amFlag});
sendMessage(e.user, readingStrings[Math.floor(Math.random() * readingStrings.length)]);
Expand Down

0 comments on commit adbf495

Please sign in to comment.