-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainPage.xaml.cs
More file actions
53 lines (43 loc) · 1.55 KB
/
MainPage.xaml.cs
File metadata and controls
53 lines (43 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
using Microsoft.Maui.Controls;
namespace TalkingStage
{
public partial class MainPage : ContentPage
{
private TalkingStageBot chatbot;
public MainPage()
{
InitializeComponent();
chatbot = new TalkingStageBot(); // Initialize the chatbot
}
private async void OnSendClicked(object sender, EventArgs e)
{
await SendMessage();
}
private async void OnEntryCompleted(object sender, EventArgs e)
{
await SendMessage();
}
private async Task SendMessage()
{
string question = UserInput.Text;
if (string.IsNullOrEmpty(question))
{
System.Diagnostics.Debug.WriteLine("User input is null or empty.");
return;
}
System.Diagnostics.Debug.WriteLine($"Sending question: '{question}' to chatbot.");
// Get response from chatbot
var (response, isFirstInteraction) = chatbot.GetResponse(question);
// Display alert if it's the first interaction
if (isFirstInteraction)
{
await DisplayAlert("Information", "Note: Different questions are identified and answered when separated by a comma, question mark, full stop or exclamation marks.", "OK");
return;
}
// Display response
ResponseLabel.Text = response;
System.Diagnostics.Debug.WriteLine($"Received response: '{response}'.");
}
}
}