Let's modify the time microservice to subscribe to the main application as soon as it has started up.
- [Instructor] Before we proceed, I want to say a word about security. I'm assuming that Iris and it's services are on a secure and safe network, and trustworthy. In real life scenarios, you would at least require some authentication token or use some sophisticated authentication methods, like a wall. In any case, you should secure your API end points. We will now modify our time service so that it announces itself to Iris. With that, I've already opened its run test file, and to send announcement, we will use super agent again.
So on top of run.gs, we add const request equals require super agent. We want to announce ourselves to the main implication as soon as the service is started up and listening. So let's use the on listening event handle that we already created. In there, right after this console.log we have here, we will add a declaration of a function and we will call it announce, so we add const announce equals parentheses, it's an E6 arrow function again and in the function body we want to request and in this case, a put request and we use back tics here again and we call http:// the local house 127 dot zero dot zero dot one and it listens on port 3000, and there we want to call the route slash service and as we are the time intent we pause time here, and the part is provided to us over the server object so we just have to add dollar brackets server dot address, and it's a function so don't forget the parentheses here, and port.
Now we have to implement the call back. This again gets an arrow object and a response object and on top V again, do some error checking so if there's an error, we will log out this error and also log out that, there was an error connecting to Iris.
And then we will sync your return from there. If there is no error, we will simply log out the reply we got from Iris that's in res.body. But now, we just declared the function, now we have to call it, so I call it here announce, and we also want to periodically repeat this announcement to tell Iris that we are still alive, so we'll add set interval announce, and we will do this every 15 times thousand milliseconds, which means 15 seconds.
Remember that all our services run on the same host, so for any new service we add, we would have to choose another port. But if we could simplify this a bit. And actually we can, we simply have to remove this hot coded port declaration in server.listen, and this will tell not just to dynamically choose a port that is free. Let's test this. Make sure that Iris is running in another window. Now let's start the service by entering node bin run.js in the terminal, and we see that there is already a result coming back from Iris, and there should be a new reply every 15 seconds.
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