How can I create ChatBot which fetch data from Azure SQL Database, Using .NET
Clash Royale CLAN TAG#URR8PPP
How can I create ChatBot which fetch data from Azure SQL Database, Using .NET
My overall idea is I have to develop a chatBot for checking Employee Leave.
For ex. Employee can enter them ID or Employee Email ID - according to email ID I want to get data from database like that particular employee Annual Leaves and Personal Leave. And gives results to User in ChatBot Prompt.
For this I have tried to connect my .NET BotAPP with Azure SQL database but I couldn't get through it.
can anyone help me to solve this question?
Here I am going to Add code of all different files
Web.Config
<appSettings>
<!-- update these with your Microsoft App Id and your Microsoft App Password-->
<add key="BotId" value="MY BOT ID" />
<add key="MicrosoftAppId" value="My APP ID" />
<add key="MicrosoftAppPassword" value="My APP PWD" />
<add key="StorageConnectionString" value="MY Database Connection String" />
Global.asax
public class WebApiApplication : System.Web.HttpApplication
protected void Application_Start()
Conversation.UpdateContainer(
builder =>
builder.RegisterModule(new AzureModule(Assembly.GetExecutingAssembly()));
// Using Azure Table Storage
var store = new TableBotDataStore(ConfigurationManager.AppSettings["AzureWebJobsStorage"]); builder.Register(c => store)
.Keyed<IBotDataStore<BotData>>(AzureModule.Key_DataStore)
.AsSelf()
.SingleInstance();
);
GlobalConfiguration.Configure(WebApiConfig.Register);
MessageController.cs
namespace Microsoft.Bot.Sample.SimpleEchoBot[BotAuthentication]
public class MessagesController : ApiController
[ResponseType(typeof(void))]
public virtual async Task<HttpResponseMessage> Post([FromBody] Activity activity)
// check if activity is of type message
if (activity != null && activity.GetActivityType() == ActivityTypes.Message)
await Conversation.SendAsync(activity, () => new EchoDialog());
else
HandleSystemMessage(activity);
return new HttpResponseMessage(System.Net.HttpStatusCode.Accepted);
private Activity HandleSystemMessage(Activity message)
if (message.Type == ActivityTypes.DeleteUserData)
else if (message.Type == ActivityTypes.ConversationUpdate)
else if (message.Type == ActivityTypes.ContactRelationUpdate)
else if (message.Type == ActivityTypes.Typing)
else if (message.Type == ActivityTypes.Ping)
return null;
EchoDialog.cs
namespace Microsoft.Bot.Sample.SimpleEchoBot
[Serializable]
public class EchoDialog : IDialog<object>
protected int count = 1;
public async Task StartAsync(IDialogContext context)
context.Wait(MessageReceivedAsync);
public async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> argument)
var message = await argument;
if (message.Text == "reset")
PromptDialog.Confirm(
context,
AfterResetAsync,
"Are you sure you want to reset the count?",
"Didn't get that!",
promptStyle: PromptStyle.Auto);
else
await context.PostAsync($"this.count++: You said message.Text");
context.Wait(MessageReceivedAsync);
public async Task AfterResetAsync(IDialogContext context, IAwaitable<bool> argument)
var confirm = await argument;
if (confirm)
this.count = 1;
await context.PostAsync("Reset count.");
else
await context.PostAsync("Did not reset count.");
context.Wait(MessageReceivedAsync);
Table Name: EmployeeLeave
EmployeeId
EmployeeEmail
AnnualLeave
PersonalLeave
EmployeeName
EmployeeOffice
EmployeeTitle
Now, can anyone help me how can I get details of particular employee ?
Thanks for replying Adil, I have tried only testing based its seems nothing. So can you suggest me How can I go ahed?
– Zankhit Patel
59 mins ago
@zakhit Please try to add this detail to your question, People like us are here to help you guys make your questions more understandable to people who can help. also your problem seems to be related to the connection of your bot to the Azure SQL Database.
– Zeeshan Adil
51 mins ago
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Please try to provide a minimal example of what you tried so far and what error did you face?
– Zeeshan Adil
1 hour ago