<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Slack &#8211; Xojo Programming Blog</title>
	<atom:link href="https://blog.xojo.com/tag/slack/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.xojo.com</link>
	<description>Blog about the Xojo programming language and IDE</description>
	<lastBuildDate>Wed, 21 Sep 2016 18:17:37 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>Write a Slackbot in Less Than 20 Lines of Code</title>
		<link>https://blog.xojo.com/2016/01/12/write-a-slackbot-in-less-than-20-lines-of-code/</link>
		
		<dc:creator><![CDATA[Paul Lefebvre]]></dc:creator>
		<pubDate>Tue, 12 Jan 2016 00:00:00 +0000</pubDate>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[Cats]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[Slack]]></category>
		<category><![CDATA[Web Service]]></category>
		<guid isPermaLink="false">http://blogtemp.xojo.com/2016/01/12/write-a-slackbot-in-less-than-20-lines-of-code/</guid>

					<description><![CDATA[Learn how to create a Slackbot for Slack in just a few lines of Xojo code.]]></description>
										<content:encoded><![CDATA[<p><strong>What is Slackbot?</strong></p>
<p>Slack has an API called &#8220;slash commands&#8221; that lets a user type a slash (/) followed by a command name in order to perform a special action. For example, Slack has <a href="https://get.slack.help/hc/en-us/articles/201259356-Using-slash-commands">many built-in slash commands</a>, one example is /help. Here&#8217;s how you can easily add your own slash commands using a Xojo web app and the HandleSpecialURL (or HandleURL) method.</p>
<p>Your slash command makes an HTTP request to your Xojo web service app. The web services does its thing and then returns the result back to Slack to display.</p>
<h2><span id="more-288"></span>A Xojo Web Service</h2>
<p>For demonstration, I&#8217;m going to show you how to create a Slackbot that returns a &#8220;cat fact&#8221;. The slash command will be /catfact. When you use the /catfact command, Slack calls a Xojo web service which then makes a call to the <a href="http://catfacts-api.appspot.com/doc.html">Cat Fact API</a>, parses the resulting JSON and returns an interesting cat fact back to Slack to display in your channel.</p>
<p><img decoding="async" style="width: 320px; display: block; margin-left: auto; margin-right: auto;" title="coding_cat.png" src="https://blog.xojo.com/wp-content/uploads/2016/01/coding_cat.pngt1466486449161ampwidth320" sizes="(max-width: 320px) 100vw, 320px" alt="coding_cat.png" width="320" /></p>
<p>As I&#8217;ve covered in a couple <a href="http://developer.xojo.com/webinar-web-services">Web Services webinars</a> last year, it is pretty easy to make a web service using Xojo. For this example, create a new web project and name it CatFact.</p>
<p>First you will create a simple method that will fetch a Cat Fact. Create a method on the App object, <strong>GetCatFact As String</strong>, with this code:</p>
<pre>// New request came in, so create a new HTTPSocket
Dim catSocket As New HTTPSocket

// Get a cat fact and wait for it to be returned
Dim factData As String = catSocket.Get("http://catfacts-api.appspot.com/api/facts?number=1", 30)

// Once the cat fact is returned, parse the JSON and send it to the original requester.
Dim jsonText As Text = DefineEncoding(factData, Encodings.UTF8).ToText
Dim jsonDict As Xojo.Core.Dictionary = Xojo.Data.ParseJSON(jsonText)
Dim facts() As Auto = jsonDict.Value("facts")

// Extract the fact text from the JSON
Dim fact As Text
If facts.Ubound &gt;= 0 Then
  fact = facts(0)
End If

Return fact</pre>
<p>In this Xojo project you&#8217;ll now create a simple web page UI to test that calling the Cat Fact API works. On the default page (WebPage1), add a Button and a TextField. In the Button&#8217;s Action event handler, add this code:</p>
<pre>CatFactArea.Text = App.GetCatFact</pre>
<p>Run the web app and on click the button. You should see a cat fact appear in the Text Area. The fact I got was:</p>
<p><strong>The cat has 500 skeletal muscles (humans have 650).</strong></p>
<p>Now you can add the code to process the web service request. Add the HandleSpecialURL event to the App object and use this code:</p>
<pre>If Request.Path = "CatFact" Then
  Request.Print(GetCatFact)
  Return True
End If</pre>
<p>You can test this by running the web project and then in a new tab entering the API URL, which displays a cat fact in the browser:</p>
<pre>http://127.0.0.1:8080/api/CatFact</pre>
<h2>Hook Up Web Service to Slack</h2>
<p>Now that you know the web service works, the next step is to hook it up to Slack. But before you can do that, you have to host the web app somewhere on the Internet; Slack can&#8217;t see your local web app! For this example, I&#8217;ve published the Cat Fact web service to <a href="http://developer.xojo.com/xojo-cloud">Xojo Cloud</a> because it&#8217;s fast and easy. This is the URL to the Cat Fact web service on Xojo Cloud:</p>
<pre>http://demos.xojo.com/CatFacts/index.cgi/api/CatFact</pre>
<p>Now you need to go to your Slack team settings to <a href="https://my.slack.com/services/new/slash-commands">add a slash command</a>. On that screen you&#8217;ll want to set the name of the <strong>Command</strong> to &#8220;/catfact&#8221; and the <strong>URL</strong> to &#8220;http://demos.xojo.com/CatFacts/index.cgi/api/CatFact&#8221; (the URL from above). Also change the <strong>Customize Name</strong> field to &#8220;CatFact&#8221;. You can ignore all the other fields and click the Save Integration button at the bottom.</p>
<p>That&#8217;s it. The slash command is now active. Head on over to your Slack team and type /catfact into a channel. You&#8217;ll get back a fact from &#8220;CatFact&#8221;.</p>
<p><img fetchpriority="high" decoding="async" title="SlackbotCatFact.png" src="https://blog.xojo.com/wp-content/uploads/2016/01/SlackbotCatFact.pngt1466486449161ampwidth578ampheight151" sizes="(max-width: 578px) 100vw, 578px" alt="SlackbotCatFact.png" width="578" height="151" /></p>
<p>And it took less than 20 lines of code! You can now use this technique to integrate your own web services into Slack.</p>
<p>By default, only you will see the cat fact returned by the Slashbot; it is not broadcast to the entire channel. You can change this by returning specifically formatted JSON rather than just a text string (as described on the <a href="https://api.slack.com/slash-commands">Slack Commands API page</a>).</p>
<p>If you come up with a great slash command and want to make it available to the world, you can attach it to a <a href="https://api.slack.com/slack-apps">Slack app</a> and publish it to the <a href="https://slack.com/apps">App Directory</a>. The steps for this are also in the <a href="https://api.slack.com/slash-commands">Slash Commands API page</a>.</p>
<p style="text-align: center;"><!--HubSpot Call-to-Action Code --> <span id="hs-cta-wrapper-7bcc3f87-4442-4a30-90b2-c9264729660a" class="hs-cta-wrapper"> <span id="hs-cta-7bcc3f87-4442-4a30-90b2-c9264729660a" class="hs-cta-node hs-cta-7bcc3f87-4442-4a30-90b2-c9264729660a"><br />
<!-- [if lte IE 8]>


<div id="hs-cta-ie-element"></div>


<![endif]--> <a href="http://blog.xojo.com/2015/10/01/cats-up-using-httpsocket-with-the-cat-rest-api/" target="_blank"><img decoding="async" id="hs-cta-img-7bcc3f87-4442-4a30-90b2-c9264729660a" class="hs-cta-img aligncenter" style="border-width: 0px;" src="https://blog.xojo.com/wp-content/uploads/2016/01/7bcc3f87-4442-4a30-90b2-c9264729660a.png" alt="Use HTTPSocket with Cat REST API" width="432" height="73" /></a> </span><script src="https://js.hscta.net/cta/current.js" charset="utf-8">// <![CDATA[
<script type="text/javascript"><![CDATA[ hbspt.cta.load(608515, '7bcc3f87-4442-4a30-90b2-c9264729660a', {});
// ]]&gt;</script></span><br />
<!-- end HubSpot Call-to-Action Code --></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Using Slack with Xojo</title>
		<link>https://blog.xojo.com/2015/11/30/using-slack-with-xojo/</link>
		
		<dc:creator><![CDATA[Paul Lefebvre]]></dc:creator>
		<pubDate>Mon, 30 Nov 2015 00:00:00 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[Slack]]></category>
		<category><![CDATA[UI]]></category>
		<guid isPermaLink="false">http://blogtemp.xojo.com/2015/11/30/using-slack-with-xojo/</guid>

					<description><![CDATA[A Xojo library for communicating with Slack.]]></description>
										<content:encoded><![CDATA[<p><a href="https://slack.com/">Slack</a> is a new business communication tool that is <a href="http://www.inc.com/magazine/201512/jeff-bercovici/slack-company-of-the-year-2015.html">taking the world by storm</a>. Here&#8217;s how you can use it with your Xojo apps.</p>
<p><span id="more-341"></span></p>
<p>As their tagline says, it&#8217;s a &#8220;messaging app for teams&#8221;. It&#8217;s also free to use (with a paid version also available) so it is easy for anyone to try.<img decoding="async" title="" src="https://blog.xojo.com/wp-content/uploads/2015/11/slack-logo.jpgt1466486449161ampwidth578ampheight259" sizes="(max-width: 578px) 100vw, 578px" width="578" height="259" /></p>
<p>Slack is pretty slick, making it incredibly easy to text chat with others on your team. I think it is much better than trying to use tools like iMessage, AIM or Skype for text chatting. With slack you can have multiple &#8220;channels&#8221; to keep converstations focused and attach files/images to a post. Slack has also been utterly reliable for me, unlike issues I&#8217;ve run into with iMessage and AIM.</p>
<p>To be fair, Slack doesn&#8217;t really offer anything all that new with regards to text chatting, but it integrates it all in a clean UI that is easily accessible by anyone.</p>
<p>Slack also has a <a href="https://api.slack.com/web">web api</a>, which of course works with Xojo. Back in September <a href="http://developer.xojo.com/webinar-using-slack">I did a webinar on a Slack library</a> It shows you how to allow your Xojo apps to post messages to a Slack channel and to get other information about your Slack teams and channels. This library is included in with the Xojo 2015 Release 3.1 examples (Communication/Web Services/Slack).</p>
<p>And now this Slack library is available on GitHub to make it easier to accept community contributions.</p>
<p><a href="https://github.com/xojo/slack">https://github.com/xojo/slack</a></p>
<p>To use the Slack library, you create an AuthToken for a Slack team account at the <a href="https://api.slack.com/web">Slack API site</a> (be sure to log in first).</p>
<p>Then you drag Slack.Connector onto your layout and call the Slack.Connector.SetAuthToken method with your token. The Open event handler is often a good place for this:</p>
<pre>SlackConnector.SetAuthToken("AFERE34323FJDK5") ' this is not an actual token</pre>
<p>Once authorized, you can call Connector methods to post message or get information about the Slack team and channels, with results returned to event handlers on Connector.</p>
<p>Refer to the <a href="https://github.com/xojo/slack">ReadMe on the GitHub page</a> for more information.</p>
<p>I hope you find it useful!</p>
<p><span id="hs-cta-wrapper-9e86dfb8-7d24-487b-a044-9a461c7f16ca" class="hs-cta-wrapper"><span id="hs-cta-9e86dfb8-7d24-487b-a044-9a461c7f16ca" class="hs-cta-node hs-cta-9e86dfb8-7d24-487b-a044-9a461c7f16ca"> <!-- [if lte IE 8]>


<div id="hs-cta-ie-element"></div>


<![endif]--> <a href="https://www.youtube.com/watch?v=D_iMQAjaxLA" target="_blank"><img loading="lazy" decoding="async" id="hs-cta-img-9e86dfb8-7d24-487b-a044-9a461c7f16ca" class="hs-cta-img aligncenter" style="border-width: 0px; margin: 0 auto; display: block; margin-top: 20px; margin-bottom: 20px;" src="https://blog.xojo.com/wp-content/uploads/2015/07/9e86dfb8-7d24-487b-a044-9a461c7f16ca.png" alt="Version Control Video Git" width="645" height="104" align="middle" /></a></span></span></p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
