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

Feature: #1 Other types of graphs #27

Merged
merged 6 commits into from
Jul 2, 2016
Merged

Feature: #1 Other types of graphs #27

merged 6 commits into from
Jul 2, 2016

Conversation

ddruker
Copy link
Collaborator

@ddruker ddruker commented Jun 30, 2016

Hey @dblock ,

To add enhanced graphs in a slack message interactive buttons needed to be included in the market model. Slack's formatting for interactive buttons can be found here.

interactive_graph_with_buttons

Clicking on each button will render the appropriate chart for that stock. If charts are set to off, then no chart or buttons will be rendered.

Slack handles a button click in a message by making a POST request to a publicly accessible endpoint, which I created in slack_endpoint.rb.

The following configurations are necessary for this work:

  • You must specify a Request URL in Interactive Messages
  • That URL must point directly to your deployed Heroku URL with the correct endpoint, which has been configured as /api/graph. For example my URL for testing purposes was the following
    https://sleepy-eyrie-81347.herokuapp.com/api/graph
  • If you haven't already, you must include a new environment variable called SLACK_VERIFICATION_TOKEN and set it equal to the verification token found in the App Credentials. This token is being used to verify that the message is coming directly from a Slack channel and its usage is highly suggested by Slack for security purposes.

Also please note the changes to both quote_spec.rb and documentation_spec.rb. All tests should complete without errors.

Please let me know if you run into any issues. This was fun!

Thanks,

David

ddruker added 2 commits June 27, 2016 11:58
Updated Market model to include buttons in formatted Slack object.
Added condition to Market model to render stock quote's correct graph.
…cture, which now includes interactive buttons and a callback id.

Refactored Market model per RuboCop.
attachments: [slack_attachment]
}
else
fail 'Message token is not actually coming from Slack.'
Copy link
Owner

Choose a reason for hiding this comment

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

This should be a 401 via error! ..., see https://github.com/ruby-grape/grape#raising-exceptions. With fail it's a 500, the server has failed, but in this case the problem is the client's data, so we want a 401.

Copy link
Owner

Choose a reason for hiding this comment

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

Add a test for this API endpoint for some basics, like parsing a good payload, and a non-matching SLACK_VERIFICATION_TOKEN.

Copy link
Owner

Choose a reason for hiding this comment

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

And this should be a one-liner as a guard:

error! ... unless token == ...

@dblock
Copy link
Owner

dblock commented Jun 30, 2016

This is awesome. Made some small-ish comments, I'd like the API fix at the least here before merging, please.

I'd like to make this a premium feature, so buttons would render, but clicking on them would not work or buttons don't render. You don't have to do it in this PR, I can take care of it later - the number of teams is growing fast and I am not having much success breaking even on hosting :(

You win at a lifetime premium subscription on market.playplay.io obviously, let me know the team name!

@@ -37,6 +37,9 @@ Announce that you sold a symbol.

Display current positions. Optionally specify a user to display someone else's current positions.

####Interactive Chart Buttons
Copy link
Owner

Choose a reason for hiding this comment

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

Add a space after #### and an empty line below to make nice.

ddruker added 3 commits July 1, 2016 17:33
…n-matching verification tokens.

Updated README with animated GIF and styling.
Added parameter validation to slack_endpoint and renamed class to GraphEndpoint.
@ddruker
Copy link
Collaborator Author

ddruker commented Jul 2, 2016

Hey @dblock,

I made the fixes to the API, added the appropriate tests and altered the market model to take in optional arguments. And you have your animated Gif :)

Thanks,

David

@@ -1,4 +1,5 @@
require 'slack-market/api/endpoints/teams_endpoint'
require 'slack-market/api/endpoints/subscriptions_endpoint'
require 'slack-market/api/endpoints/status_endpoint'
require 'slack-market/api/endpoints/slack_endpoint'
Copy link
Owner

Choose a reason for hiding this comment

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

Should be called graph_endpoint.rb.

I think you had a good point wrt making it "slack" vs. "graph", but there're two things that are difficult in computer science, caching and naming :) I prefer domain-specific names, in my experience they just always last longer.

@dblock
Copy link
Owner

dblock commented Jul 2, 2016

Great! It's almost there. I would have merged without that rogue p and file names.

@ddruker
Copy link
Collaborator Author

ddruker commented Jul 2, 2016

@dblock, Thanks for your quick feedback. I updated the file names and removed that rogue p

@dblock dblock merged commit 3baf5fb into dblock:master Jul 2, 2016
@dblock
Copy link
Owner

dblock commented Jul 2, 2016

Merged this, closes #1, thanks so much! Will get it deployed soon, I'm wrapping up making this a cheap, but paid service. What's your team id? Want to give you a free subscription.

dblock pushed a commit that referenced this pull request Jul 2, 2016
* Created /api/graph endpoint for Interactive Slack Messages.
Updated Market model to include buttons in formatted Slack object.
Added condition to Market model to render stock quote's correct graph.

* Updated model and endpoint spec to account for new slack message structure, which now includes interactive buttons and a callback id.
Refactored Market model per RuboCop.

* downgraded firefox to version 46.01 for selenium-webdriver tests

* created spec to slack_endpoint test for parsing a good payload and non-matching verification tokens.
Updated README with animated GIF and styling.
Added parameter validation to slack_endpoint and renamed class to GraphEndpoint.

* refactored slack_endpoint_spec

* Changed slack_endpoint to be called graph_endpoint
@dblock
Copy link
Owner

dblock commented Jul 2, 2016

Having configured this on market.playplay.io I see your point about the graph endpoint - slack only supports a single action URL. Probably /slack/action or maybe just your original slack suggestion was indeed better.

Feel free to PR an update, otherwise I'll get to it at some point.

@ddruker
Copy link
Collaborator Author

ddruker commented Jul 2, 2016

Hey @dblock, I'll make the PR. I find it interesting that they only support a single URL. Do you have any idea as to why that's the case?

This was a lot of fun to code. I'd like to continue adding features and fixing bugs if possible. Are there any other issues I can work on?

The team name is doodlebots and the id is T1L7R335Z

@dblock
Copy link
Owner

dblock commented Jul 2, 2016

I've upgraded the team.

I've added you as collaborator of the repo. You should continue making pull requests, this is just in case a piano falls on my head and to help out with future committers/PRs! Spend as much or as little time as you can/want, no obligations.

There're a bunch of neat feature requests in issues. I like #20, #14 and #16 for example.

@ddruker ddruker deleted the other-types-of-graphs branch July 2, 2016 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants