<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>slack on smarx.com</title>
    <link>https://smarx.com/tags/slack/</link>
    <description>Recent content on smarx.com</description>
    <language>en-us</language>
    <managingEditor>smarx@smarx.com (Steve Marx)</managingEditor>
    <webMaster>smarx@smarx.com (Steve Marx)</webMaster>
    <lastBuildDate>Sun, 06 Sep 2020 19:56:34 -0400</lastBuildDate>
    
        <atom:link href="https://smarx.com/tags/slack/index.xml" rel="self" type="application/rss+xml" />
    
    
    <item>
      <title>Shove It Up Your Bot: an Intro to Slack Bots</title>
      <link>https://smarx.com/posts/2020/09/shove-it-up-your-bot-an-intro-to-slack-bots/</link>
      <pubDate>Sun, 06 Sep 2020 19:56:34 -0400</pubDate>
      <author>smarx@smarx.com (Steve Marx)</author>
      <guid>https://smarx.com/posts/2020/09/shove-it-up-your-bot-an-intro-to-slack-bots/</guid>
      <description>&lt;p&gt;In &lt;a href=&#34;https://en.wikipedia.org/wiki/The_List_(The_Office)&#34;&gt;season 8, episode 1 of The Office&lt;/a&gt;, Stanley says that his &amp;ldquo;thing now&amp;rdquo; is to pretend to help people by giving lengthy instructions and then saying &amp;ldquo;&amp;hellip; and shove it up your butt!&amp;rdquo;&lt;/p&gt;
&lt;iframe src=&#34;https://giphy.com/embed/13pqs1VizKyWzK&#34; width=&#34;320&#34; height=&#34;230&#34; frameBorder=&#34;0&#34; class=&#34;giphy-embed mx-auto&#34; allowFullScreen&gt;&lt;/iframe&gt;
&lt;p&gt;Inspired by this episode, I created a Slack bot a couple years ago called &amp;ldquo;shove it up your bot&amp;rdquo;. It&amp;rsquo;s been entertaining me ever since. In this post, I&amp;rsquo;ll walk through the basics of this type of mention/response Slack bot and share the full code for the bot.&lt;/p&gt;





    





&lt;figure class=&#34;flex flex-col items-center&#34;&gt;
    
    &lt;img class=&#34;mx-auto&#34; src=&#34;https://smarx.com/posts/2020/09/shove-it-up-your-bot-an-intro-to-slack-bots/waves-featured.png&#34; width=&#34;457&#34; height=&#34;262&#34;&gt;
    
    
&lt;/figure&gt;

&lt;h2 id=&#34;multiple-slack-apis&#34;&gt;Multiple Slack APIs&lt;/h2&gt;
&lt;p&gt;The Slack API comes in a few different &lt;a href=&#34;https://api.slack.com/apis&#34;&gt;flavors&lt;/a&gt;. The two most popular and relevant are these:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Web API&lt;/strong&gt; &amp;ndash; A straightforward HTTP-based API. This can be used to create channels, send messages, search chat history, etc. Requests here are initiated by your code. I use this to send messages from &lt;code&gt;@shoveitupyourbot&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Events API&lt;/strong&gt; &amp;ndash; A webhook-based API. You configure what events your app is subscribed to, and when one occurs, Slack makes a request to the bot&amp;rsquo;s registered URL with the event as a payload. I use the events API to know when somebody mentions the bot, e.g. &amp;ldquo;&lt;code&gt;@shoveitupyourbot&lt;/code&gt; make scrambled eggs&amp;rdquo;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Note that not every Slack app is a bot. For example, integrations like &lt;a href=&#34;https://slack.com/apps/A0F827J2C-giphy&#34;&gt;Giphy&lt;/a&gt; post messages on behalf of existing users. Bots are specifically the type of Slack integration where the app appears in chat under its own name.&lt;/p&gt;
&lt;h2 id=&#34;permissions&#34;&gt;Permissions&lt;/h2&gt;
&lt;p&gt;To do anything in Slack, a bot needs to be added to a Slack instance, which grants it an OAuth token. That OAuth token is tied to a set of &lt;em&gt;scopes&lt;/em&gt;, which define what the bot can do.&lt;/p&gt;
&lt;p&gt;A bot like &lt;code&gt;@shoveitupyourbot&lt;/code&gt; needs to do exactly two things:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;See when it&amp;rsquo;s mentioned in chat. This is the &lt;code&gt;app_mentions:read&lt;/code&gt; scope.&lt;/li&gt;
&lt;li&gt;Send chat messages. This is the &lt;code&gt;chat:write&lt;/code&gt; scope.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The first scope will actually be added for you if you subscribe to that event, but the second scope needs to be added manually.&lt;/p&gt;





    




    


&lt;figure class=&#34;flex flex-col items-center&#34;&gt;
    
    &lt;a href=&#34;https://smarx.com/posts/2020/09/shove-it-up-your-bot-an-intro-to-slack-bots/scopes.png&#34; data-lightbox=&#34;331bed3898a13939cacd46cdd637b3aa&#34; data-title=&#34;Slack UI for managing OAuth scopes.&#34; &gt;
    
    &lt;img class=&#34;mx-auto border p-4&#34; src=&#34;https://smarx.com/posts/2020/09/shove-it-up-your-bot-an-intro-to-slack-bots/scopes_hu1b81c8284451eab74addc24a761f34a0_66981_448x0_resize_lanczos_2.png&#34; width=&#34;448&#34; height=&#34;278&#34;&gt;
    
    &lt;/a&gt;
    
    
    &lt;figcaption&gt;
        &lt;p&gt;Slack UI for managing OAuth scopes.&lt;/p&gt;
    &lt;/figcaption&gt;
    
&lt;/figure&gt;

&lt;h2 id=&#34;subscribing-to-events&#34;&gt;Subscribing to events&lt;/h2&gt;
&lt;p&gt;You can subscribe to events directly in the Slack app UI. Here I&amp;rsquo;ve subscribed to just the &lt;code&gt;app_mention&lt;/code&gt; event, which is triggered any time a user @-mentions the bot (e.g. &amp;ldquo;&lt;code&gt;@shoveitupyourbot&lt;/code&gt; hello&amp;rdquo;):&lt;/p&gt;





    




    


&lt;figure class=&#34;flex flex-col items-center&#34;&gt;
    
    &lt;a href=&#34;https://smarx.com/posts/2020/09/shove-it-up-your-bot-an-intro-to-slack-bots/subscribe.png&#34; data-lightbox=&#34;10df1120f7c9a506ff17b18c22bc8a8b&#34; data-title=&#34;Slack UI for managing event subscriptions.&#34; &gt;
    
    &lt;img class=&#34;mx-auto border p-4&#34; src=&#34;https://smarx.com/posts/2020/09/shove-it-up-your-bot-an-intro-to-slack-bots/subscribe_hu900422852d83bbfeb74ac54e10293715_59003_448x0_resize_lanczos_2.png&#34; width=&#34;448&#34; height=&#34;210&#34;&gt;
    
    &lt;/a&gt;
    
    
    &lt;figcaption&gt;
        &lt;p&gt;Slack UI for managing event subscriptions.&lt;/p&gt;
    &lt;/figcaption&gt;
    
&lt;/figure&gt;

&lt;h3 id=&#34;mutual-authentication&#34;&gt;Mutual authentication&lt;/h3&gt;
&lt;p&gt;When a bot sends an HTTP request to Slack, it uses an OAuth bearer token to authenticate itself, but it&amp;rsquo;s also important to do the reverse. When Slack sends an HTTP request with an event, it cryptographically signs that message so the bot can be sure it comes from Slack.&lt;/p&gt;
&lt;p&gt;The signature scheme is pretty simple:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;X-Slack-Request-Timestamp&lt;/code&gt; contains a Unix timestamp for the request. Apps should check that this is reasonably close to the current time to avoid replay attacks.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;X-Slack-Signature&lt;/code&gt; contains the HMAC-SHA256 digest for the string &lt;code&gt;v0:&amp;lt;timestamp&amp;gt;:&amp;lt;request body&amp;gt;&lt;/code&gt;, computed with a shared &amp;ldquo;signing secret&amp;rdquo;, and prefixed with &lt;code&gt;v0=&lt;/code&gt;. (&lt;code&gt;v0&lt;/code&gt; is a version string to allow for future signature schemes.)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;An app can validate a request by recomputing the signature and checking it against the header.&lt;/p&gt;
&lt;p&gt;An appropriate library/SDK will handle this for you, but it&amp;rsquo;s not too hard to implement manually. I implemented &lt;code&gt;@shoveitupyourbot&lt;/code&gt; in Go without the help of a Slack library:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-go&#34; data-lang=&#34;go&#34;&gt;&lt;span class=&#34;kd&#34;&gt;func&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;b&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;*&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;bot&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;eventHandler&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;w&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;http&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;ResponseWriter&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;r&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;*&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;http&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;Request&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
	&lt;span class=&#34;nx&#34;&gt;body&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;_&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;:=&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;ioutil&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;ReadAll&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;r&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;Body&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

	&lt;span class=&#34;c1&#34;&gt;// Check for a recent timestamp to avoid replay attacks.
&lt;/span&gt;&lt;span class=&#34;c1&#34;&gt;&lt;/span&gt;	&lt;span class=&#34;nx&#34;&gt;t&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;_&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;:=&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;strconv&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;Atoi&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;r&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;Header&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;Get&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;X-Slack-Request-Timestamp&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;
	&lt;span class=&#34;k&#34;&gt;if&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;math&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;Abs&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;float64&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;time&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;Now&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;().&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;Unix&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;int64&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;t&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)))&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;300&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
		&lt;span class=&#34;nx&#34;&gt;w&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;WriteHeader&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;http&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;StatusForbidden&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
		&lt;span class=&#34;nx&#34;&gt;fmt&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;Fprintln&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;w&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;Timestamp differs by more than 5 minutes.&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
		&lt;span class=&#34;k&#34;&gt;return&lt;/span&gt;
	&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
	&lt;span class=&#34;c1&#34;&gt;// Compute HMAC-SHA256
&lt;/span&gt;&lt;span class=&#34;c1&#34;&gt;&lt;/span&gt;	&lt;span class=&#34;nx&#34;&gt;mac&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;:=&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;hmac&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;New&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;sha256&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;New&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;[]&lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;byte&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;b&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;secret&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;
	&lt;span class=&#34;nx&#34;&gt;fmt&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;Fprintf&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;mac&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;v0:%d:%s&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;t&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;body&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
	&lt;span class=&#34;nx&#34;&gt;digest&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;:=&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;mac&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;Sum&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;kc&#34;&gt;nil&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
	&lt;span class=&#34;c1&#34;&gt;// Reject invalid signatures
&lt;/span&gt;&lt;span class=&#34;c1&#34;&gt;&lt;/span&gt;	&lt;span class=&#34;k&#34;&gt;if&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;r&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;Header&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;Get&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;X-Slack-Signature&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;!=&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;v0=&amp;#34;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;+&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;hex&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;EncodeToString&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;digest&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
		&lt;span class=&#34;nx&#34;&gt;w&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;WriteHeader&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;http&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;StatusForbidden&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
		&lt;span class=&#34;nx&#34;&gt;fmt&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;Fprintln&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;w&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;Invalid signature.&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
		&lt;span class=&#34;k&#34;&gt;return&lt;/span&gt;
	&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id=&#34;handling-the-challenge-request&#34;&gt;Handling the challenge request&lt;/h3&gt;
&lt;p&gt;Here&amp;rsquo;s a fun way to spam a web server! Create a Slack app, add it to a busy Slack instance, and subscribe to a bunch of events with a URL that points to the victim server. Slack avoids this type of HTTP spam attack much like many services avoid email spam, by validating the address before sending any additional messages.&lt;/p&gt;
&lt;p&gt;When you register an event URL, Slack makes a single request to that URL with a &lt;code&gt;challenge&lt;/code&gt; parameter in JSON, e.g.:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-json&#34; data-lang=&#34;json&#34;&gt;&lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
    &lt;span class=&#34;nt&#34;&gt;&amp;#34;type&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;url_verification&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;
    &lt;span class=&#34;nt&#34;&gt;&amp;#34;challenge&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;abc123...&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;
    &lt;span class=&#34;nt&#34;&gt;&amp;#34;token&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;...&amp;#34;&lt;/span&gt;
&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;(The &lt;code&gt;token&lt;/code&gt; field is a now-deprecated alternative to the request signature above.)&lt;/p&gt;
&lt;p&gt;If the server fails to respond with the same string that&amp;rsquo;s found in the &lt;code&gt;challenge&lt;/code&gt; field, verification fails, and no more requests will be sent to that server.&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s the &lt;code&gt;@shoveitupyourbot&lt;/code&gt; code for handling the challenge request:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-go&#34; data-lang=&#34;go&#34;&gt;&lt;span class=&#34;kd&#34;&gt;var&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;msg&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;eventMessage&lt;/span&gt;
&lt;span class=&#34;nx&#34;&gt;json&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;Unmarshal&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;body&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;msg&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;c1&#34;&gt;// For challenge requests, just echo the challenge field
&lt;/span&gt;&lt;span class=&#34;c1&#34;&gt;&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;if&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;len&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;msg&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;Challenge&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
    &lt;span class=&#34;nx&#34;&gt;fmt&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;Fprintln&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;w&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;msg&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;Challenge&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
    &lt;span class=&#34;k&#34;&gt;return&lt;/span&gt;
&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id=&#34;handling-bot-mentions&#34;&gt;Handling bot mentions&lt;/h3&gt;
&lt;p&gt;Event HTTP requests can be described by the &lt;code&gt;eventMessage&lt;/code&gt; struct below (and the nested &lt;code&gt;event&lt;/code&gt; struct):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-go&#34; data-lang=&#34;go&#34;&gt;&lt;span class=&#34;kd&#34;&gt;type&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;event&lt;/span&gt; &lt;span class=&#34;kd&#34;&gt;struct&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
	&lt;span class=&#34;nx&#34;&gt;Type&lt;/span&gt;     &lt;span class=&#34;kt&#34;&gt;string&lt;/span&gt;
	&lt;span class=&#34;nx&#34;&gt;Text&lt;/span&gt;     &lt;span class=&#34;kt&#34;&gt;string&lt;/span&gt;
	&lt;span class=&#34;nx&#34;&gt;Channel&lt;/span&gt;  &lt;span class=&#34;kt&#34;&gt;string&lt;/span&gt;
	&lt;span class=&#34;nx&#34;&gt;ThreadTS&lt;/span&gt; &lt;span class=&#34;kt&#34;&gt;string&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;`json:&amp;#34;thread_ts&amp;#34;`&lt;/span&gt;
&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;

&lt;span class=&#34;kd&#34;&gt;type&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;eventMessage&lt;/span&gt; &lt;span class=&#34;kd&#34;&gt;struct&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
	&lt;span class=&#34;nx&#34;&gt;Challenge&lt;/span&gt;   &lt;span class=&#34;kt&#34;&gt;string&lt;/span&gt;
	&lt;span class=&#34;nx&#34;&gt;Event&lt;/span&gt;       &lt;span class=&#34;nx&#34;&gt;event&lt;/span&gt;
	&lt;span class=&#34;nx&#34;&gt;AuthedUsers&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;[]&lt;/span&gt;&lt;span class=&#34;kt&#34;&gt;string&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;`json:&amp;#34;authed_users&amp;#34;`&lt;/span&gt;
&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;There are a lot more fields in the actual requests, but these are the only ones relevant to responding to bot mentions and the initial challenge request. This code detects a mention and prepares a response:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-go&#34; data-lang=&#34;go&#34;&gt;&lt;span class=&#34;kd&#34;&gt;var&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;msg&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;eventMessage&lt;/span&gt;
&lt;span class=&#34;nx&#34;&gt;json&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;Unmarshal&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;body&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;msg&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;o&#34;&gt;...&lt;/span&gt;

&lt;span class=&#34;c1&#34;&gt;// When the bot is mentioned, respond with a funny message
&lt;/span&gt;&lt;span class=&#34;c1&#34;&gt;&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;if&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;msg&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;Event&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;Type&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;==&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;app_mention&amp;#34;&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
    &lt;span class=&#34;c1&#34;&gt;// Remove the bot&amp;#39;s user ID from the message.
&lt;/span&gt;&lt;span class=&#34;c1&#34;&gt;&lt;/span&gt;    &lt;span class=&#34;c1&#34;&gt;// E.g. &amp;#34;&amp;lt;@U123abc&amp;gt; how do you make scrambled eggs?&amp;#34; --&amp;gt;
&lt;/span&gt;&lt;span class=&#34;c1&#34;&gt;&lt;/span&gt;    &lt;span class=&#34;c1&#34;&gt;//      &amp;#34;how do you make scrambled eggs?&amp;#34;
&lt;/span&gt;&lt;span class=&#34;c1&#34;&gt;&lt;/span&gt;    &lt;span class=&#34;nx&#34;&gt;user&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;:=&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;msg&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;AuthedUsers&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;
    &lt;span class=&#34;nx&#34;&gt;text&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;:=&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;strings&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;TrimSpace&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;
        &lt;span class=&#34;nx&#34;&gt;strings&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;ReplaceAll&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;msg&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;Event&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;Text&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;&amp;lt;@&amp;#34;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;+&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;user&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;+&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;&amp;gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;

    &lt;span class=&#34;c1&#34;&gt;// Make a response
&lt;/span&gt;&lt;span class=&#34;c1&#34;&gt;&lt;/span&gt;    &lt;span class=&#34;nx&#34;&gt;response&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;:=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;getInstructions&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;text&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I&amp;rsquo;m going to skip over the implementation of &lt;code&gt;getInstructions&lt;/code&gt;, but it uses the &lt;a href=&#34;https://github.com/PuerkitoBio/goquery&#34;&gt;goquery&lt;/a&gt; to parse pages loaded from &lt;a href=&#34;https://www.wikihow.com/&#34;&gt;wikiHow&lt;/a&gt;. It then chops off some of the steps and replaces them with &amp;ldquo;Shove it up your butt.&amp;rdquo; You can read the code in &lt;a href=&#34;https://github.com/smarx/shoveitupyourbot/blob/master/instructions.go&#34;&gt;&lt;code&gt;instructions.go&lt;/code&gt;&lt;/a&gt; in case you&amp;rsquo;re curious.&lt;/p&gt;





    





&lt;figure class=&#34;flex flex-col items-center&#34;&gt;
    
    &lt;img class=&#34;mx-auto&#34; src=&#34;https://smarx.com/posts/2020/09/shove-it-up-your-bot-an-intro-to-slack-bots/robot.png&#34; width=&#34;355&#34; height=&#34;167&#34;&gt;
    
    
&lt;/figure&gt;

&lt;h2 id=&#34;sending-a-message&#34;&gt;Sending a message&lt;/h2&gt;
&lt;p&gt;To send a message, I&amp;rsquo;m using the web API, specifically &lt;a href=&#34;https://api.slack.com/methods/chat.postMessage&#34;&gt;&lt;code&gt;chat.postMessage&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The following Go struct describes the shape of the JSON body:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-go&#34; data-lang=&#34;go&#34;&gt;&lt;span class=&#34;kd&#34;&gt;type&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;chatMessage&lt;/span&gt; &lt;span class=&#34;kd&#34;&gt;struct&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
	&lt;span class=&#34;nx&#34;&gt;Channel&lt;/span&gt;  &lt;span class=&#34;kt&#34;&gt;string&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;`json:&amp;#34;channel&amp;#34;`&lt;/span&gt;
	&lt;span class=&#34;nx&#34;&gt;Text&lt;/span&gt;     &lt;span class=&#34;kt&#34;&gt;string&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;`json:&amp;#34;text&amp;#34;`&lt;/span&gt;
	&lt;span class=&#34;nx&#34;&gt;ThreadTS&lt;/span&gt; &lt;span class=&#34;kt&#34;&gt;string&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;`json:&amp;#34;thread_ts,omitempty&amp;#34;`&lt;/span&gt;
&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If supplied, the &lt;code&gt;thread_ts&lt;/code&gt; field tells Slack what thread a message is being sent to. It just mirrors the &lt;code&gt;thread_ts&lt;/code&gt; field received in the &lt;code&gt;app_mention&lt;/code&gt; event.&lt;/p&gt;
&lt;p&gt;In addition to this JSON body, it&amp;rsquo;s important to attach the OAuth token in the &lt;code&gt;Authorization&lt;/code&gt; header. This code sends the response chat message:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-go&#34; data-lang=&#34;go&#34;&gt;&lt;span class=&#34;c1&#34;&gt;// Send the message to the right channel/thread
&lt;/span&gt;&lt;span class=&#34;c1&#34;&gt;&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;c&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;:=&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;chatMessage&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;msg&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;Event&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;Channel&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;response&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;msg&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;Event&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;ThreadTS&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;span class=&#34;nx&#34;&gt;j&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;_&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;:=&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;json&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;Marshal&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;c&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;nx&#34;&gt;req&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;_&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;:=&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;http&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;NewRequest&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;http&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;MethodPost&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;
    &lt;span class=&#34;s&#34;&gt;&amp;#34;https://slack.com/api/chat.postMessage&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;bytes&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;NewBuffer&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;j&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;
&lt;span class=&#34;nx&#34;&gt;req&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;Header&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;Set&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;Content-Type&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;application/json&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;nx&#34;&gt;req&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;Header&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;Set&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;Authorization&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;Bearer &amp;#34;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;+&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;b&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;token&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;c1&#34;&gt;// OAuth token
&lt;/span&gt;&lt;span class=&#34;c1&#34;&gt;&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;http&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;DefaultClient&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;Do&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;req&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;development-tip-use-ngrok&#34;&gt;Development tip: use ngrok&lt;/h2&gt;
&lt;p&gt;While developing a bot, you need a publicly-accessible HTTP(S) URL were the challenge request and other events can be sent.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://ngrok.com/&#34;&gt;&lt;code&gt;ngrok&lt;/code&gt;&lt;/a&gt; is a tool that forwards public URL requests to a port on your local computer. (You can build something similar on your own with &lt;a href=&#34;https://dev.to/jackfiallos/create-your-own-tunnelling-like-ngrok-does-kg4&#34;&gt;SSH tunneling&lt;/a&gt;.)&lt;/p&gt;
&lt;p&gt;This is incredibly helpful when you&amp;rsquo;re rapidly iterating on your code and want to be able to see changes instantly without deploying them.&lt;/p&gt;





    





&lt;figure class=&#34;flex flex-col items-center&#34;&gt;
    
    &lt;img class=&#34;mx-auto&#34; src=&#34;https://smarx.com/posts/2020/09/shove-it-up-your-bot-an-intro-to-slack-bots/ssh.png&#34; width=&#34;317&#34; height=&#34;141&#34;&gt;
    
    
&lt;/figure&gt;

&lt;h2 id=&#34;deploying-to-heroku&#34;&gt;Deploying to Heroku&lt;/h2&gt;
&lt;p&gt;The bot code can be deployed anywhere, but I chose to use Heroku. It&amp;rsquo;s lightweight, and I&amp;rsquo;m already familiar with it. This isn&amp;rsquo;t a Heroku tutorial, so I&amp;rsquo;m not going to go into much depth in this section.&lt;/p&gt;
&lt;p&gt;Heroku figures out what version of Go to run from a comment in &lt;code&gt;go.mod&lt;/code&gt;. This isn&amp;rsquo;t strictly necessary because there&amp;rsquo;s always a default, but I like to be explicit:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-go&#34; data-lang=&#34;go&#34;&gt;&lt;span class=&#34;c1&#34;&gt;// +heroku goVersion go1.14
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;A few quick commands with &lt;code&gt;git&lt;/code&gt; and &lt;code&gt;heroku&lt;/code&gt; create a new Heroku app and add the necessary environment variables:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;$ heroku create siuyb
$ git init
$ heroku git:remote --app siuyb
$ &lt;span class=&#34;nb&#34;&gt;echo&lt;/span&gt; web: ~/bin/shoveitupyourbot &amp;gt;&amp;gt; Procfile
$ heroku config:set &lt;span class=&#34;nv&#34;&gt;TOKEN&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;xoxb-... &lt;span class=&#34;nv&#34;&gt;SECRET&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;...
$ git commit -am &lt;span class=&#34;s2&#34;&gt;&amp;#34;initial commit&amp;#34;&lt;/span&gt;
$ git push heroku master
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;a-note-about-multitenancy&#34;&gt;A note about multitenancy&lt;/h2&gt;
&lt;p&gt;I engineered this bot to only work in one Slack instance at a time because it has a hardcoded OAuth token. It could easily be extended to work in multiple Slack instances by looking up the appropriate token based on the &amp;ldquo;authenticated user&amp;rdquo; in the event payload.&lt;/p&gt;
&lt;p&gt;This would be a necessary step before distributing this app broadly.&lt;/p&gt;
&lt;h2 id=&#34;full-source-code&#34;&gt;Full source code&lt;/h2&gt;
&lt;p&gt;You can find the full source code at &lt;a href=&#34;https://github.com/smarx/shoveitupyourbot&#34;&gt;github.com/smarx/shoveitupyourbot&lt;/a&gt;.&lt;/p&gt;





    





&lt;figure class=&#34;flex flex-col items-center&#34;&gt;
    
    &lt;img class=&#34;mx-auto&#34; src=&#34;https://smarx.com/posts/2020/09/shove-it-up-your-bot-an-intro-to-slack-bots/suppository.png&#34; width=&#34;475&#34; height=&#34;142&#34;&gt;
    
    
&lt;/figure&gt;

</description>
    </item>
    
  </channel>
</rss>
