Sample Bot - Stockbot for Slack

Check out this sample bot that shows off several of Slack's API methods

Stockbot Header

About Stockbot

Stockbot is a sample bot written for Slack, that can quickly lookup real time quotes for a particular ticker. Stockbot utilizes several of Slack's API methods and features, including a Slash Command, Events, the Web API, Attachments, and Buttons. Stockbot is a great starter bot to build a better understanding of Slack's API, Botkit, and general bot building.

Using Glitch, you'll be able to easily clone Stockbot's code, host Stockbot inside Glitch (no need for local config!), and get a working copy in minutes! You can also view Stockbot's source code on Github.

Stockbot Preview Convo

Feel free to try out Stockbot in the link below, or follow along with this guide to get your own Stockbot up and working.

Add to Slack

Stockbot Features

Stockbot showcases several features of Slack's API and features.

  • Slash Commands
    • Stockbot has a Slash Command, /stockbot. This slash command exemplifies Slack's implementation of an outgoing webhook, where an explicit user driven event (typing /command) sends a payload to your bot, followed by your bot taking some action based on the user's input.
  • Events
    • Stockbot also subscribes to Events, and listens to 'cash tags', i.e. $NFLX. During your setup of Stockbot on Slack, you'll be asked to subscribe to multiple message events in several mediums (direct messages, channels, etc.). Any time a message is sent to these specified mediums, your bot is sent an event. Stockbot will run a regular expression match on each of these events, searching for text that matches $CASHTAG. On a match, Stockbot will respond to that event.
  • API Methods
    • Stockbot also shows an example of how a method can be called and used, by using the reactions.add API Method. When this method is called, Stockbot will interact with the message that triggered the event or slash command, by adding an emoji reaction (upwards or downwards trending graph) to that message.
  • Attachments
    • Stockbot uses attachments to enrich the user experience. A clickable title link, short bits of information stored in fields, a graphical representation of the stock's status, and color are all included to present the stock's data in an easy-to-read fashion.
  • Buttons
    • Lastly, Stockbot has a 🔎 Show More Info button that populates the attachment with additional fields. In setting up Stockbot, you'll be asked to set up Interactive Messages, so that when a user clicks the button, Slack will send a payload to your bot containing information about the button that was clicked. We are also using chat.update here to provide a seamless presentation by updating the original message instead of sending an entirely new one.

Setting up your own Stockbot

Thanks to the awesome tool that is Glitch, setting your own Stockbot is as easy as clicking the Remix on Glitch button below.

Remix on Glitch

Once you've opened up this link, you'll be taken to a more detailed explanation of how to set up your new Stockbot. At the top of the page, you'll see a button that says Remix This 🎤. From here, you can follow the Read Me that's included in Stockbot's code to get everything set up.

results matching ""

    No results matching ""