From the course: Microsoft Teams Bot Development

Writing your bot logic

From the course: Microsoft Teams Bot Development

Writing your bot logic

- [Instructor] Now with our project set up let's start writing our actual bot code. So, I'm going to create a couple of variables to reference the botbuilder stk. So, one will be required botbuilder and Intellisense and Visual Studio Code is just amazing. It makes things so much easier. Restify, let's go in and add that as well, restify. Now, the first thing I'll do I'll go in a create a connector. So, remember channels? You connect a channel through a connector so I'm going to say, const connector is equal to new builder ChatConnector. So, it's the simplest connector we can create. Next I'll say const bot is equal to new builder UniversalBot and I'll specify the connector. And notice at the next parameter here you see is either one dialogue or multiple dialogues array you know like water falls down. Now, I'll have an array here but really what I want to do is that I want to create the worlds simplest bot that basically anything you say to it it will respond with, hello world. So, it's a hello world bot. Now, you can make this a lot more complicated and we will see some more compelling examples of that I won't be able to cover every single example because this is not a course on bots but basically the dialogue step is represented as a function which accepts three parameters but right now we need only one which is the session parameter. So, this lambda expression auto function will use that syntax and basically whatever I receive from the user I send back, "hello world". Now, the bot framework will require storage. So, we need to specify the storage for it, like this. And lets just use dev storage to keep things simple. I'm going to say, new builder memory bot storage. Remember this is good for only dev purposes. That's it. That's my bot code. Now the next thing I need to do is that I need to host this using restify. So, I'll say const server is equal to restify create server server.post and I will expose this on a URL called /api/messages, connector listen and server.listen but we'll specify a port. I will choose 3978. And the reason I've chose 3978 is because I will also use a tool that Microsoft has provided to us that allows me to test bots easily. And using that tool, I'll be able to test my bot but that tool by default talks to 3978. I can change it, but just to avoid some typing I am targeting port 3978. Great, it's time to run the bot.

Contents