-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGoogleKeepPlugin.cs
More file actions
99 lines (76 loc) · 2.76 KB
/
GoogleKeepPlugin.cs
File metadata and controls
99 lines (76 loc) · 2.76 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
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
using System.ComponentModel;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.SemanticKernel;
namespace FirstPlugin;
public class GoogleKeepPlugin
{
private readonly HttpClient _httpClient;
public GoogleKeepPlugin()
{
_httpClient = new HttpClient();
}
[KernelFunction("list_notes")]
[Description("Lists all notes from Google Keep.")]
public async Task<List<GoogleKeepNote>> ListNotesAsync(/*[Description("The authentication token for Google Keep API")] string authToken*/)
{
// if (string.IsNullOrWhiteSpace(authToken))
// {
// throw new ArgumentException("Authentication token must be provided.", nameof(authToken));
// }
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "ea4ae6fe72bd7bb028344573f5ab4e3e794cd0b7");
var response = await _httpClient.GetAsync("https://keep.googleapis.com/v1/notes");
if (!response.IsSuccessStatusCode)
{
throw new HttpRequestException($"Failed to fetch notes: {response.ReasonPhrase}");
}
var content = await response.Content.ReadAsStringAsync();
var notes = JsonSerializer.Deserialize<GoogleKeepNotesResponse>(content);
return notes?.Notes ?? new List<GoogleKeepNote>();
}
}
public class GoogleKeepNotesResponse
{
[JsonPropertyName("notes")]
public List<GoogleKeepNote> Notes { get; set; } = new();
[JsonPropertyName("nextPageToken")]
public string? NextPageToken { get; set; }
}
public class GoogleKeepNote
{
[JsonPropertyName("name")]
public string Name { get; set; } = string.Empty;
[JsonPropertyName("title")]
public string Title { get; set; } = string.Empty;
[JsonPropertyName("createTime")]
public string CreateTime { get; set; } = string.Empty;
[JsonPropertyName("updateTime")]
public string UpdateTime { get; set; } = string.Empty;
[JsonPropertyName("trashed")]
public bool Trashed { get; set; }
[JsonPropertyName("body")]
public GoogleKeepNoteBody? Body { get; set; }
}
public class GoogleKeepNoteBody
{
[JsonPropertyName("text")]
public string? Text { get; set; }
[JsonPropertyName("list")]
public GoogleKeepNoteListContent? List { get; set; }
}
public class GoogleKeepNoteListContent
{
[JsonPropertyName("listItems")]
public List<GoogleKeepNoteListItem> ListItems { get; set; } = new();
}
public class GoogleKeepNoteListItem
{
[JsonPropertyName("text")]
public string Text { get; set; } = string.Empty;
[JsonPropertyName("checked")]
public bool Checked { get; set; }
[JsonPropertyName("childListItems")]
public List<GoogleKeepNoteListItem>? ChildListItems { get; set; }
}