The first microservice we build will tell us the time at any given location. Let's sketch out how we will build this.
- [Instructor] After the main application has reached the point where it can call action based on incoming intent, it is now time to create the first service. The time service should return the local time for a given location. Earlier on we created a basic express application layout consisting of a bin/run.js file and the server/service.js file. If you'll use the same layout again now, please use the version you saved earlier, copy and name it iris-time. I've prepared it already and placed it on my desktop here.
Now I'm opening Visual Studio Code again. Select File, Open, and I'm selecting this iris-time folder. Clicking on Open again, and first let's look into this package.json file. And here we will also change the package name to iris-time. Now let's open bin/run.js and we have to make two changes here, can you spot them? First, we want to change the port here in this listen directive, because our main application already listens on port 3000 so we have to change it here and I select 3010 here.
And we should also change the log message here in line 10 to read iris-time instead of iris. Now we can try this out so I click on View, Integrated Terminal again. And I'm running node bin/run.js. And I get the message "IRIS-Time is listening "on 3010 in development mode." Next we will create the express route that will receive the request from the main application.
For that we open service.js. And right here on line five we add a new route. So we add service.get, this means for every get request to the URI /service/:location and if we want to call this method, then request, response, and next. I will explain it in a second.
So for every request to services, we assume that the next pass is the location. We define a request parameter by prefixing it with a colon here, and I'm using /service as prefix here so that we could also add some other rules. Because otherwise this location route would become more or less a catch-all. And in this case, we just return res.json and in this JSON object we put result and this should be req.params.location.
And then we simply reply with a JSON object containing the location we just passed in. So let's rerun this application now. And now we open our browser and call localhost:3010 and then the route service and as location we choose Berlin, for instance. And as expected, I get the JSON object back that contains the location we queried before.
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