Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow user to create hangouts from slack #943

Merged
merged 18 commits into from
Sep 5, 2018

Conversation

gauravchl
Copy link
Member

@gauravchl gauravchl commented Aug 17, 2018

Flow:

  1. Slack user post message in slack channel
  2. [DONE]Slack send this message to Codebuddies Meteor server.
  3. [DONE]Meteor server read this message using Event subscription in real time https://api.slack.com/events-api
  4. [DONE]Meteor server read the slack user's email and timezone who posted the above message using slack's web API
  5. [DONE]Meteor server find the user in it's db whos email is same as the user who posted the message in slack. If user is found then it process to next step.
  6. [DONE] Meteor server parse the message and read topic, start/end date and create hangout.
  7. [DONE] On successful hangout creation Meteor server send back a message to slack channel.
  8. [DONE] For now don't allow one user to create more than 5 hangouts per day from slack.
  9. [DONE] Update response message, it should return hangout url like:
    Hangout created successfully for 25 minutes, starting from Mon Sep. 3rd 2018. 5:00 pm Asia/Kolkota. 
     Go to https://codebuddies.org/hangout/Tu84XrgG8kzTMxsNy to edit or join the hangout.
    

Links:

@@ -1,18 +1,24 @@
var bodyParser = require('body-parser');
var bodyParser = require("body-parser");
import webhooks from "/server/slack/webhooks.js";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eslint problems? ping @distalx

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sebbel It's coming from my Prettier config. Will revert and disable for this project.

server/routes.js Outdated
result
) {
if (err) {
res.statusCode = 404;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

404 is reserved for page not found. not sure, but I think for a server side error, we should use 500

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sebbel +1

const { slackAppToken } = Meteor.settings;

if (!token || token !== slackAppToken) {
res.statusCode = 404;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above

webhooks.processEvent(event);
return;
}
res.statusCode = 404;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above

processEvent(event) {
console.log("webhook.processEvent", event);
const { user: slackUserId, text, type, channel, ts } = event || {};
if (type !== "message") return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eslint should throw here ping @distalx

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sebbel Do we use any style guide for codebuddies? I can't find any eslint config.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sebbel What do you mean by eslint throwing here? Throwing an error?

@gauravchl We have https://docs.codebuddies.org/code-contribution/coding_style, and Prettier does automatically updates the code in the PR to be a certain style. Let me know if you need help with any of the remaining tasks!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lpatmo Thanks Linda! I will tackle remaining tasks this weekend, i might need some help with setting up slack app on production env.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gauravchl Thanks, sounds great! I will be working on CB too this weekend. Re: hosting -- were you thinking something like a DigitalOcean droplet? We should have funds still in our DigitalOcean account from the DO sponsorship. That's where we're hosting https://github.com/codebuddies/greetbot at the moment. (Not sure if it's possible to build on top of greetbot for the purposes of this integration.)

Copy link
Member Author

@gauravchl gauravchl Aug 31, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lpatmo Cool! Re Hosting: Naah, it doesn't need any extra droplet or server. It will run directly inside Meteor server where codebuddies.org is running. Just need to add some new keys(slack app tokens) inside settings-production.json, i'll PM you. And then install the bot on codebuddies slack channel.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that makes sense. I can def. add keys to both settings-development.json (so we can test it out) and then to settings-production.json for the release.

@gauravchl
Copy link
Member Author

@sebbel Thanks for the review!

@gauravchl gauravchl changed the title WIP: Allow user to create hangouts from slack Allow user to create hangouts from slack Sep 2, 2018
@gauravchl
Copy link
Member Author

@lpatmo @sebbel
The bot(cb_jarvis) is ready: https://youtu.be/eDrZC0uv8hA

How to test on development machine

  1. Start the app on your localhost

  2. Install ngrok and run ngrok http 3000, this will allow your local host to accept incoming requests from slack API. copy the https url(ie: https://6b935d58.ngrok.io)

  3. Send me your email and i will add you to slack app(cb_jarvis) and slack channel https://gauravchl.slack.com/ created for testing this bot.

  4. Go to cb_jarvis's settings https://api.slack.com/apps/ACAB1TCTD/event-subscriptions and paste the copied ngrok url to Request URL field like: https://6b935d58.ngrok.io/webhook/slack , Click verify.

  5. Go to https://gauravchl.slack.com/ and ping cb_jarvis. Try:

@cb_jarvis help 
@cb_jarvis list hangout 
@cb_jarvis create hangout, tomorrow at 5pm, Learn css 
Try different dates like: Friday at 2 pm
Note: It uses Chrono natural language date parser: https://github.com/wanasit/chrono 

How to deploy to production

  1. Install app to codebuddies slack channel
  2. Set Request URL to https://codebuddies.org/webhook/slack
  3. Copy oAuth token and set it to settings-production.json
  4. Deploy it to production
  5. Verify Request URL from slack app setting.
  6. Test it!

@lpatmo
Copy link
Member

lpatmo commented Sep 3, 2018

https://www.youtube.com/watch?v=eDrZC0uv8hA&feature=youtu.be is super exciting. Thanks for recording the demo!

An idea/suggestion: After a hangout is successfully created, could the return message on Slack could contain the URL to the hangout that was just created? This way, the user could get to it to edit the details about the hangout, assuming they're logged into the site already.

So the message might say:
Hangout created successfully for 25 minutes, starting from Mon Sep. 3rd 2018. 5:00 pm Asia/Kolkota. Go to https://codebuddies.org/hangout/Tu84XrgG8kzTMxsNy to edit or join the hangout.

I'm assuming that the payload from the site could include the post ID that's created, of course. If the URL isn't possible, we could say something like:
... Go to https://codebuddies.org/hangout to find your hangout and edit it if necessary`

@gauravchl
Copy link
Member Author

@lpatmo done 😎
screen shot 2018-09-04 at 6 22 17 pm

@lpatmo lpatmo closed this Sep 5, 2018
@lpatmo lpatmo deleted the feature/hangout-from-slack branch September 5, 2018 16:12
@lpatmo lpatmo added [state] closed the issue is now closed, see comments for more information and removed Waiting For Review labels Sep 5, 2018
@lpatmo lpatmo restored the feature/hangout-from-slack branch September 5, 2018 16:14
@lpatmo lpatmo reopened this Sep 5, 2018
@ghost ghost assigned lpatmo Sep 5, 2018
@ghost ghost added the [state] in-progress this issue is currently being worked on label Sep 5, 2018
@lpatmo lpatmo added Waiting For Review [state] in-progress this issue is currently being worked on and removed [state] closed the issue is now closed, see comments for more information Waiting For Review labels Sep 5, 2018
Copy link
Member

@lpatmo lpatmo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 🎆 🔥

@lpatmo lpatmo merged commit fd6b20a into codebuddies:master Sep 5, 2018
@ghost ghost removed the [state] in-progress this issue is currently being worked on label Sep 5, 2018
@lpatmo lpatmo added the [state] closed the issue is now closed, see comments for more information label Sep 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[state] closed the issue is now closed, see comments for more information
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants