<?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 Archives - Blog IT</title>
	<atom:link href="https://blogit.create.pt/tag/slack/feed/" rel="self" type="application/rss+xml" />
	<link>https://blogit.create.pt/tag/slack/</link>
	<description>Create IT blogger community</description>
	<lastBuildDate>Thu, 10 Jan 2019 12:46:20 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>
	<item>
		<title>Playing with Azure Functions: Creating a Slack bot</title>
		<link>https://blogit.create.pt/pedrovala/2016/06/27/playing-with-azure-functions-part-i-creating-a-slack-bot/</link>
					<comments>https://blogit.create.pt/pedrovala/2016/06/27/playing-with-azure-functions-part-i-creating-a-slack-bot/#comments</comments>
		
		<dc:creator><![CDATA[Pedro Vala]]></dc:creator>
		<pubDate>Mon, 27 Jun 2016 16:40:45 +0000</pubDate>
				<category><![CDATA[Cloud]]></category>
		<category><![CDATA[Microsoft Azure]]></category>
		<category><![CDATA[azure]]></category>
		<category><![CDATA[Azure Functions]]></category>
		<category><![CDATA[Bot]]></category>
		<category><![CDATA[Event]]></category>
		<category><![CDATA[Slack]]></category>
		<category><![CDATA[Trigger]]></category>
		<category><![CDATA[Webhook]]></category>
		<guid isPermaLink="false">http://blogit.create.pt/pedrovala/?p=811</guid>

					<description><![CDATA[<p>Past March, Microsoft launched the preview of Azure Functions, often referred as an Amazon Lambda competitor. This being my first post about this topic, I will briefly introduce Azure Functions and show how to create a simple bot for Slack with Azure Functions. In the following posts, I will dive into more advanced features. Basic [&#8230;]</p>
<p>The post <a href="https://blogit.create.pt/pedrovala/2016/06/27/playing-with-azure-functions-part-i-creating-a-slack-bot/">Playing with Azure Functions: Creating a Slack bot</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Past March, Microsoft launched the preview of <a href="https://azure.microsoft.com/pt-pt/services/functions/">Azure Functions</a>, often referred as an Amazon Lambda competitor.</p>
<p>This being my first post about this topic, I will briefly introduce Azure Functions and show how to create a simple bot for Slack with Azure Functions.</p>
<p>In the following posts, I will dive into more advanced features.</p>
<h2>Basic Concepts</h2>
<p>Azure Functions is a way of running code in the cloud without having to think of stuff like infrastructure or scalability.</p>
<p>It’s designed to be a fast development, fast deployment technology for an event-driven world. Therefore, in Functions we configure triggers for events and then Functions are executed based on them.</p>
<p>You can write code in the most common languages, such as C#, Node.Js, PHP, Python, Bash or Powershell.</p>
<p>And coolest of all, you only pay for what you use.</p>
<h2>Creating my first function</h2>
<p>Creating a function is super easy.</p>
<p>In this simple walkthrough, you will be creating a Bot connected to <a href="https://slack.com/">Slack</a>.</p>
<p>Access your <a href="https://portal.azure.com">Azure Portal</a> (if you don’t have a subscription, you can create a trial <a href="https://azure.microsoft.com/pt-pt/free/">here</a>) and create a new <strong>Function App</strong>.</p>
<p><a href="http://blogit-create.com/wp-content/uploads/2016/06/image.png"><img decoding="async" style="padding-top: 0px;padding-left: 0px;padding-right: 0px;border-width: 0px" title="image" src="http://blogit-create.com/wp-content/uploads/2016/06/image_thumb.png" alt="image" width="244" height="175" border="0" /></a></p>
<p>When configuring the Azure Function, one thing to notice is that you can choose between a <strong>Classic</strong> or a <strong>Dynamic</strong> App Service plan. This is related to <a href="https://azure.microsoft.com/en-us/pricing/details/functions/">pricing</a>.</p>
<p>On a Classic Plan, your function is regarded as a typical App, just like any other Web App in your plan. So, you don’t have any additional cost. On the other hand, the Dynamic Plan, enables you to pay on-demand, which means Azure provides and manages all the resources and you just need to pay the time that the code runs.</p>
<p><a href="http://blogit-create.com/wp-content/uploads/2016/06/image-1.png"><img decoding="async" style="padding-top: 0px;padding-left: 0px;margin: 0px;padding-right: 0px;border-width: 0px" title="image" src="http://blogit-create.com/wp-content/uploads/2016/06/image_thumb-1.png" alt="image" width="141" height="244" border="0" /></a></p>
<p>In this case, I opted for an already existing App Plan to save some money from my subscription.</p>
<p>When you access your Function App the first time, you can really see why this is a preview version, judging by the way it looks. Azure provides a quick start menu, that enables us to quickly create &#8211; what I presume to be &#8211; the most common scenarios for Azure Functions.</p>
<p><a href="http://blogit-create.com/wp-content/uploads/2016/06/image-2.png"><img decoding="async" style="padding-top: 0px;padding-left: 0px;padding-right: 0px;border-width: 0px" title="image" src="http://blogit-create.com/wp-content/uploads/2016/06/image_thumb-2.png" alt="image" width="244" height="143" border="0" /></a></p>
<p>On the left panel, you have a shortcut to create a new function, which shows more options. Currently, Azure Functions leverages 8 different languages and has 45 available scenarios for development acceleration. But you can always choose to start from scratch with an empty template.</p>
<p>Choose the language <strong>C#</strong> and the <strong>Generic Webhook</strong> scenario from the dropdowns, rename the function to “HelloBot” and press <strong>Create</strong>.</p>
<p><a href="http://blogit-create.com/wp-content/uploads/2016/06/image-3.png"><img decoding="async" style="padding-top: 0px;padding-left: 0px;padding-right: 0px;border-width: 0px" title="image" src="http://blogit-create.com/wp-content/uploads/2016/06/image_thumb-3.png" alt="image" width="244" height="118" border="0" /></a></p>
<p>On the <strong>Develop</strong> tab, you can see the code generated by the template, the Url of the function, a logging console and even test the function. The generated function for this template, receives an HttpRequestMessage expecting a Json message with “first” and “last” properties.</p>
<p><a href="http://blogit-create.com/wp-content/uploads/2016/06/image-4.png"><img decoding="async" style="padding-top: 0px;padding-left: 0px;padding-right: 0px;border-width: 0px" title="image" src="http://blogit-create.com/wp-content/uploads/2016/06/image_thumb-4.png" alt="image" width="244" height="167" border="0" /></a></p>
<p>This code is ready to run, so before continuing, we can quickly test it by scrolling down to the end of the page and, using the test console, send a request with the following:</p>
<pre class="brush: jscript; title: ; notranslate">
{
   &quot;first&quot;: &quot;Azure&quot;,
   &quot;last&quot;: &quot;Functions&quot;
}
</pre>
<p>After pressing Run, the Output should be a 200 OK with the following body:</p>
<pre class="brush: jscript; title: ; notranslate">
{ &quot;greeting&quot;:&quot;Hello Azure Functions!&quot; }
</pre>
<p>You can also notice there was a new entry in the logs panel above, regarding this last invocation.</p>
<h2>Creating an Hello Bot for Slack</h2>
<p>In this section, we will edit the previous function and create a bot that answers to Slack messages posted in a Slack channel.</p>
<p>In first place, our function needs to be able to understand Slack messages. The Slack webhook message format is something like this:</p>
<pre class="brush: plain; title: ; notranslate">
user_name=tpo&amp;amp;token=SomeToken&amp;amp;trigger_word=googlebot%3A&amp;amp;text=sample+text&amp;amp;user_id=U2147483697&amp;amp;timestamp=1355517523.000005&amp;amp;channel_name=test&amp;amp;channel_id=C2147483705&amp;amp;team_domain=example&amp;amp;example=T0001
</pre>
<p>We need to change the code of the function to simply check if the message contains the word “Hello” and if it does, the function will simple answer “Good mooooorning Vietnam!”</p>
<pre class="brush: csharp; title: run.csx; notranslate">
using System;
using System.Net;

public static async Task&lt;object&gt; Run(HttpRequestMessage req, TraceWriter log)
{
    log.Info($&quot;Webhook was triggered!&quot;);

    string formDataStr = await req.Content.ReadAsStringAsync();
    string&#x5B;] array = formDataStr.Split('&amp;amp;amp;amp;');
    
    if(formDataStr.ToLower().Contains(&quot;hello&quot;))
    {
         return req.CreateResponse(HttpStatusCode.OK, new {
                text = $&quot;Good mooooorning Vietnam!&quot;
                });
    }

    return req.CreateResponse(HttpStatusCode.OK, new {
        text = $&quot;&quot;
    });
}
</pre>
<p>Now we can test the function using the same method as before, but this time we will send a message containing the following:</p>
<pre class="brush: plain; title: ; notranslate">
user_name=tpo&amp;amp;token=SomeToken&amp;amp;trigger_word=googlebot%3A&amp;amp;text=hello+my+friend&amp;amp;user_id=U2147483697&amp;amp;timestamp=1355517523.000005&amp;amp;channel_name=test&amp;amp;channel_id=C2147483705&amp;amp;team_domain=example&amp;amp;example=T0001
</pre>
<p>If we send a message not containing the word “hello”, the function should return an empty text message, which Slack will ignore.</p>
<h3>Bindings</h3>
<p>We are not ready yet.</p>
<p>As it is, our function is still expecting a Json message and Slack is sending messages in another format (you can try to hit your function using Postman and see the error message).</p>
<p>In order to change this, we need to access the <strong>Integrate </strong>tab, which is where we configure the <strong>bindings</strong> of our function. A binding is an abstraction so that the same code can be used to interact with different sources or outputs. Remember we chose a preconfigured scenario, which has two bindings: an Http trigger and an Http Output. I will leave more details about bindings for a dedicated post.</p>
<p>For now, just change the Http Trigger to &#8220;Standard&#8221; mode, instead of &#8220;Webhook&#8221; which only supports GitHub or Json at this point. You can leave the Authorization Level with &#8220;Function&#8221; or &#8220;Anonymous&#8221;.</p>
<h2>Configuring Slack</h2>
<p>On your Slack team, add a new Custom Integration called <a href="https://api.slack.com/outgoing-webhooks">Outgoing Webhooks</a>.</p>
<p>When configuring the Webhook, just copy the Url from the <strong>Develop </strong>tab of the Azure Function. If you notice, the url has a “code” element on the query string which is used for authentication purposes. You need to copy the full Url including that.</p>
<p>After configuring slack&#8217;s webhook, just go to the channel where you configured the webhook and write &#8220;Hello!&#8221;. Your bot should answer accordingly!</p>
<p>The post <a href="https://blogit.create.pt/pedrovala/2016/06/27/playing-with-azure-functions-part-i-creating-a-slack-bot/">Playing with Azure Functions: Creating a Slack bot</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/pedrovala/2016/06/27/playing-with-azure-functions-part-i-creating-a-slack-bot/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
