Before proceeding further, I recommend you read my first article: Getting Started with Microsoft Bot Framework.
Once you are done with creating the project as you can see there is an API Controller in Controllers folder named “MessageController”.
- [BotAuthentication]
- public class MessagesController: ApiController
- {
-
-
-
-
- public async Task < Message > Post([FromBody] Message message)
- {
- if (message.Type == "Message")
- {
-
- int length = (message.Text ? ? string.Empty).Length;
-
- return message.CreateReplyMessage($ "You sent {length} characters");
- }
- else
- {
- return HandleSystemMessage(message);
- }
- }
- }
I am changing text a little bit and my message will look like this.
-
-
-
-
- public async Task < Message > Post([FromBody] Message message)
- {
- if (message.Type == "Message")
- {
-
- return message.CreateReplyMessage($ "Raj said:{message.Text}");
- }
- else
- {
- return HandleSystemMessage(message);
- }
- }
Run your application,
If you want to run on emulator to test your calls, Install emulator form here.
Pass three things when you run Bot Emulator.
- URL - You have to mention your application url with port before api/messages.
- AppId - Defined in web.config
- AppSecret - Defined in web.config
Conclusion
In this article, we have learned how to create a bot using Microsoft Bot Framework. In next article we will see how to publish your Bot Application to Microsoft Azure. If you have any question or comments, message me on C# Corner comments section.