-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCustomActionsPlugin.cs
101 lines (82 loc) · 4.24 KB
/
CustomActionsPlugin.cs
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System.ComponentModel;
using Microsoft.SemanticKernel;
using Newtonsoft.Json;
using System.Text.Json;
using System.Linq;
using MailKit.Net.Smtp;
using MailKit.Security;
using MailKit;
using MimeKit;
/* Custom Actions Plugin: can be used to add actions to the assistant
Exposed functions:
- AddEventToCalendar: Add an event to the calendar.
- SendEMail: Send an email to a recipient with a specified subject and body.
- GetCurrentDateTime: Get the current date and time in YYYY-MM-DD format.
*/
namespace SemanticKernelConsoleCopilotDemo
{
internal sealed class CustomActionsPlugin
{
[KernelFunction, Description("Send an email to a recipient with a specified subject and body. Only one email can be sent at a time. ")]
public static string SendEMail(
[Description("The email address of the recipient. Just the email address, one email address only!")] string to,
[Description("Email subject")] string subject,
[Description("Email body")] string body) {
var message = new MimeMessage ();
message.From.Add (new MailboxAddress (ConfigurationSettings.GmailEmailSender, ConfigurationSettings.GmailEmailUsername));
message.To.Add (new MailboxAddress (to, to));
message.Subject = subject;
message.Body = new TextPart ("plain") { Text = body };
using (var client = new SmtpClient ()) {
client.Connect("smtp.gmail.com", 465, SecureSocketOptions.SslOnConnect);
client.Authenticate (ConfigurationSettings.GmailEmailUsername, ConfigurationSettings.GmailEmailAppPassword);
client.Send (message);
client.Disconnect (true);
return "Email sent successfully!";
}
}
[KernelFunction, Description("Add an event to the calendar in case adding a calendar event is requested from the end user. ")]
public static string AddEventToCalendar(
[Description("Title of the event")] string eventTitle,
[Description("Description of the event")] string eventDescription,
[Description("Location of the event")]string eventLocation,
[Description("Start date and time of the event")]string eventStartDate,
[Description("End date and time of the event")]string eventEndDate) {
// Add the event to the calendar: TODO, implement the logic here
return "Event added to the calendar!";
}
/* [KernelFunction, Description("Get the current date and time in YYYY-MM-DD format. ")]
public static string GetCurrentDateTime() {
return System.DateTime.Now.ToString("yyyy-MM-dd");
}
[KernelFunction, Description("Get the current day of the week. ")]
public static string GetCurrentWeekDay() {
return System.DateTime.Now.DayOfWeek.ToString();
}
[KernelFunction, Description("Get the events from the calendar for the specified date.")]
public static string[] CheckCalendarEventsForDate(string date) {
// Check the calendar for events on the specified date
var day = System.DateTime.Parse(date).Day;
if (day % 2 == 0) {
return new string[] { "Meeting with Mom 10:00 AM", "Lunch with Clare 1:00 PM" };
} else {
return new string[] { };
}
}
[KernelFunction, Description("Get the weather for the specified location, optionally for the specified date.")]
public static string GetWeatherForLocation(
[Description("The location for which the weather is requested.")] string location,
[Description("The date for which the weather is requested. Optinal, otherwise the current day is taken")] string date = "2024-01-01") {
// Check if the date day is an odd or even day from the date provided
var day = System.DateTime.Parse(date).Day;
if (day % 2 == 0) {
return "Weather for " + location + " is sunny.";
} else {
return "Weather for " + location + " is partly cloudy.";
}
} */
public CustomActionsPlugin()
{
}
}
}