Skip to content

Commit a481b33

Browse files
committed
feat: add mail inbox tools
Signed-off-by: Jana Peper <jana.peper@nextcloud.com>
1 parent b789065 commit a481b33

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

ex_app/lib/agent.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def call_model(
6767
Today is {CURRENT_DATE}.
6868
Intuit the language the user is using (there is no tool for this, you will need to guess). Reply in the language intuited. Do not output the language you intuited.
6969
Only use tools if you cannot answer the user without them.
70+
Always check for the mail account id before requesting a folder list.
7071
Only use the duckduckgo_results_json tool if the user explicitly asks for a web search.
7172
You can check which conversations exist using the list_talk_conversations tool, if a conversation cannot be found.
7273
You can check which calendars exist using the list_calendars tool, if a calendar can not be found.

ex_app/lib/all_tools/mail.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,39 @@ def send_email(subject: str, body: str, account_id: int, from_email: str, to_ema
4949
def get_mail_account_list():
5050
"""
5151
Lists all available email accounts including their account id
52-
:param subject: The subject of the email
53-
:param body: The body of the email
54-
:param account_id: The id of the account to send from
55-
:param to_emails: The emails to send
5652
"""
5753

5854
return nc.ocs('GET', '/ocs/v2.php/apps/mail/account/list')
55+
56+
57+
@tool
58+
@safe_tool
59+
def get_mail_folder_list(account_id: int):
60+
"""
61+
Lists all mail folders for an account. You need to get the correct account id matching the request first before using this tool.
62+
:param account_id: The id of the account to list as integer, obtainable via get_mail_account_list
63+
"""
64+
65+
return nc.ocs('GET', '/ocs/v2.php/apps/mail/mailbox/list', json={'accountId': account_id})
66+
67+
68+
@tool
69+
@safe_tool
70+
def list_mails(folder_id: int, n_mails: int = 30):
71+
"""
72+
Lists all messages in a mailbox folder. You need to get the correct folder id matching the request first before using this tool.
73+
:param folder_id: The id of the folder to list as integer, obtainable via get_mail_folder_list
74+
:param n_mails: The number of mails to receive. Optional, default is 30
75+
:return: a list of mails/messages, including timestamps
76+
"""
77+
return nc.ocs('GET', '/ocs/v2.php/apps/mail/mailbox/messages/list', json={'mailboxId': folder_id, 'limit': n_mails})
5978

6079

6180
return [
6281
send_email,
63-
get_mail_account_list
82+
get_mail_account_list,
83+
get_mail_folder_list,
84+
list_mails,
6485
]
6586

6687
def get_category_name():

0 commit comments

Comments
 (0)