Purchase Order Chat-bot application with OData endpoints using WebApi in D365 for Operations


Currently, I have given a task to integrate my Chat-bot (which is built on using Microsoft's Bot Framework) application with D365 for Operations to create and read Purchase Orders in and from D365 for Operations.

There are many blogs written on to read the D365 for Operations data entities using OData endpoints in console application with OAuth authentication.
I am mentioning some useful links for reference below:

1. Working with the Odata endpoint in Dynamics 365 for Operations.
2. Integration with Dynamics365 for Operations using OData proxy generator.

Integration of Dynamics 365 for Operations with Chat-bot application:

I have created a Chat-bot application using the Microsoft's Bot Framework.

I am sharing some code snippets which will help you guys to start with Bot Framework and OData.

Above solution explorer image shows how many projects you will need to create a Chat-bot application integrated with D365FO.

Above shown four projects:
1. AuthenticationUtility
2. ODataUtility
4. WebApplication4

1. AuthenticationUtility Project:

There are two classes in 

2. OData Utility Project:

In this project ODataClient will create ODataClient.tt file and will load all the entities information in this file.

3. Web Application Project:

It is a WebApi Application. In which we use controller class to make action for read and create records in PurchaseOrder entity and also authenticate the request using OAuth using OData endpoints for D365FO.
Please, see the screen shot below:

initConfiguration() is authenticating the OData endpoints configured in ODataUtility and OAuthenticationUtility projects show in above screen shots.

Above screen shot shows code snippet for creation of Purchase order in D365FO from Chat-bot application using OData endpoints.

4. Purchase Order Chat-bot Project:

For creating a chat-bot application. First you need to install Bot Application in your solution using Nuget Package Manager. 
Please, find the below screen shot for that:

After you install Bot Application project template.
You will able to see this type project when you try to create the chat-bot application:

After you create project with using Bot application project template.
You will below objects pre-created in you project:

As you can see chat-bot application project is a web application project with Controllers and Dialog folder are already created in this project.

MessageController.cs class handles you to and fro of messages from Chat-bot application.
RootDialog.cs class handles which dialog class to instantiate as per the business requirement.

Now, I am attaching the front-end screen shot of my Purchase Order Chat-Bot application connected with D365FO using the OData endpoint services.

As you can see, I just simply run my chat-bot application from visual studio on localhost and place my localhost url in the Bot Framework Emulator adding /api/messages in the end of the URL.

On the right bottom in the Log section chat-bot application is connected successfully with post 200 message.

Purchase Order Chat-bot application is ready and working like charm.

Thanks for your time and interest.

Each life is made up of mistakes and learning, waiting and growing, practicing patience and being persistent.

Billy Graham


Popular posts from this blog

Import General Journal Lines using SysOperation Framework in AX 2012

Mobile Development with Microsoft Technology (Xamarin) Part - 1