The microservice will now be connected to the main application and start answering questions asked over Slack.
- [Instructor] When we left the main Iris application, we had already created a timeintent route. Now all that is left is to call iris-time from there. We're still here in iris-time. The only thing I do is I make sure that it is actually running because we want to access the service then. Now in Visual Studio Code, I select File, New Window, and from there I select Open.
And I open Iris. Here we go. Now let's open the timeintent. And we want to use a SuperAgent here to call our iris-time service so I add const request equals require('superagent'). Now here instead of returning just this placeholder message we remove that and first let's store the location here into variable location equals intentData.location.value.
Next we want to call this service we just created, so it will request, it's a get request and we use back ticks here and we call http://localhost on port 3010/service. And here we now add the location object we just stored with a dollar and curly brackets.
The callback now is again e6 error function that takes an error and a result and in the function body we again do some error checking so if there is an error or the status code of the result is not 200, so anything than okay, or we didn't get a result back, we want to log out the error and also log out the response body so that we see what we actually got back here.
And we will also return the callback with, in this case, no error, but the message we see on Slack in back ticks, we add "I had a problem "finding out "the time in" dollar, curly brackets and our location. So if anything goes wrong, we will see a message on Slack. If everything went fine, it will simply return the callback again with no error, but with back tick string and we will return in dollar, curly brackets location, it is now dollar, curly brackets, res.body.result.
Now let's start this and see what happens, so I tap in node bin/run.js. And I open Slack again and I ask, "What's the time in Vienna, Iris?" And obviously she doesn't understand us yet, so let's look back into her code and we see there that we get the error back that it could not extract our intent, so let's look into slackClient, where this error is returned, it's here.
And we see that here an exclamation mark is missing because we have to negate that. So let's restart this again. Go back into Slack, and ask a question again. And we get back "In Vienna, Iris, it is now Tuesday, "September the 20th and it's 9:54 PM." But actually, as we already saw before, we tend to add this iris string to our location and that's not what we want.
And I think we should simply solve this quite pragmatically so I go back into Visual Studio Code and into timeintent. And here we have our location and here where we store the location, we just add a simple replacement. So we add replace parenthesis and two slashes. This marks a regular expression and this regular expression has to read ,.?iris and in the end an i and we want to replace that with an empty string.
As a set, this is a so-called regular expression and regular expressions are quite powerful. So if you're interested in this topic, please read on on that, you can do very very much with them. So now, after we save that, we run Iris again. Open Slack, and we ask again. "What's the time in Vienna, Iris?" Press Return, and we get the reply, "In Vienna, it is now Tuesday, September" and so on.
This is now the result that we expected, so we now created a bot that actually can tell us the local time of any place in the world. You can now try out a few more cities.
After explaining some basics about Node.js and microservices, Daniel shows you how to sketch out the planned architecture for your application and get the boilerplate code, modules, and credentials in place. Next, he shows how to create a bot user in Slack, connect to Slack, and post messages. He also shows you how to get your bot to process variations in text by creating logic that delegates the processing of intent to dedicated modules. Lastly, he shows how to register additional services and he covers how to use monitoring to identify architectural or performance issues.
- Using Slack APIs
- Sketching out a Slack bot architecture
- Setting up a project and choosing modules
- Creating and naming your bot
- Connecting to Slack
- Setting up and using natural language processing
- Routing by intents
- Implementing geocoding and time calculation
- Adding and monitoring services