erichartline / tiger-slackbot

Node.js Slackbot to help with technical interviews
0 stars 0 forks source link

Figure out how to build feature for daily questions #1

Open asteed21 opened 7 years ago

asteed21 commented 7 years ago

Looks like interactive messaging is the name of the functionality. Slack's tutorial here is a really good walkthrough of the functionality we will need, including the api commands and hooking it up to our slack app.

https://api.slack.com/interactive-messages

asteed21 commented 7 years ago

I also scoured through this repo to get a feel for how they did it.

https://github.com/slackapi/sample-message-menus-node

It's basically more of the same as the tutorial @wildlifehexagon posted, just need to configure the proper functions to handle the data when interacting with the various routes we will be using. I think the next steps include mapping that process more specifically. A couple of questions:

  1. How do we want the interaction to look? Is it more of a yes/no opt-in or do we provide a couple of steps to gather extra information?

  2. Do we want any of the steps to include menus? Maybe something like frequency of questions or similar. This would be more involved, but I'm willing to pursue it if we think it will add enough benefit.

erichartline commented 7 years ago

Oops, missed these questions earlier.

1) For now, a simple opt-in is probably sufficient. We can change that later if we want to add more features or make the bot more conversational.

2) Same thoughts as #1 -- I think for now we will be OK with just doing the daily feature, but it's something we could look into once we get everything up and running.

erichartline commented 7 years ago

Possible way to set up daily reminders? https://api.slack.com/methods/reminders.add

asteed21 commented 7 years ago

@wildlifehexagon I think that will work. I'm pretty close to cracking the daily sign up interactive message bit, will try to commit it before I sleep tonight. From there, we should be able to manage the reminder aspect with the same question call function we already created and the method you've outlined. At least that makes sense at first glance...

erichartline commented 7 years ago

Nice! I'm curious what you come up with for the interactive messages. I thought I had the right setup for it in the daily branch, but it's still not responding to the right prompts.

asteed21 commented 7 years ago

So this is super frustrating, but maybe you already knew that! I pulled the daily branch you had and am working off of that. I got it working with a slash command, but because I think we want the bot to be more interactive, I wanted to get it working with the bot responses. We can always default to the slash command if needed though.

Anyway, the issue is that the RTM API doesn't recognize attachments, so we can't post interactive messages with that (so the sendMessage method of the RTM api is out). BUT, the web API has a chat.postMessage method that does everything we need. I added a web API instance in the bot class, then extended the bot class with an interact() method that called this API method with data from another respondTo function in index.js that recognized "daily". All off this worked fine, except the web API method keeps giving me the same error no matter what I do. It's a invalid_array_arg error. According to the docs, this is from an issue with the JSON formatting of the request, but I'm kind of stuck. I tried encoding/stringifying with no luck and even when I use the examples I find verbatim I'm getting the same thing. No clue what it could be, but I may try again tomorrow and then revert to slashcommand or webhook if it won't work.

erichartline commented 7 years ago

The slash command may be the best way to go, actually. It sounds like it would be easier to implement, and it may be potentially less chaotic in the chat room too (so a user doesn't inadvertently trigger the bot in regular conversation).

That is a weird error though. Could you push your latest branch when you get a chance?

asteed21 commented 7 years ago

That sounds good. Sorry for not pushing sooner, wanted to split the one with the issue to a separate branch so we can tinker with it separately. Will push the slash command tonight when I get home so we can keep progressing.

asteed21 commented 7 years ago

Went ahead and pushed to the daily branch. The Web API stuff is in the daily-WebAPI branch now if you want to have a go at it...would still be relevant for any interactive messages we want to do with just the bot (eg category selection maybe?).

In terms of the changes, I basically set up endpoints with the express server for authentication and daily questions. I also changed the port on the server and used ngrok to tunnel the localhost so that slack could verify a url to interact with. The downside with not having a server at this point is that you have to go into slack and update the following with the new ngrok URL each time you run ngrok to test:

Interactive Messages > Request URL > set to [ngrok url]/actions Slash Commands > Dailyquestions > set to [ngrok url]/dailyquestions OAuth & Permissions > Request URLs > set or add [ngrok url]/oauth

I already added the app to the team, so we should be good there, but if you decide to test it in another team then you will have to add the app to that one.

Anywho, once ngrok is running, those URLs are updated and you run node index.js from the updated directory, just use /dailyquestions to get the message to appear (just to you). Clicking the button then sends a post request with to the /actions destination. I haven't gotten into processing that data outside of confirming the choice on screen, but that is theoretically where we will do something with the data management soon I think.

Not sure if that's enough to close this issue or if we want to keep it open until all of the data processing is worked out.

erichartline commented 7 years ago

Further thoughts after digging in some more...

It looks like in order to do cron jobs with Heroku, we have to use their own Scheduler add-on: https://scheduler.heroku.com/dashboard

I'm not sure how feasible this will be with our current design. If I'm interpreting this correctly, we would have to disallow the user to pick a time to receive the question, and it seems it can only trigger via a command line argument (i.e. npm start). Not 100% sure of the best way to tackle this issue.

I'm going to make a note of this feature being "in progress" and prep the rest for shipment.