|
| 1 | +from agentmail import AgentMail |
| 2 | +from typing import Optional, List |
| 3 | + |
| 4 | + |
| 5 | +client = AgentMail() |
| 6 | + |
| 7 | + |
| 8 | +def list_inboxes(limit: Optional[int] = None, last_key: Optional[str] = None): |
| 9 | + """ |
| 10 | + List inboxes. |
| 11 | +
|
| 12 | + Args: |
| 13 | + limit: The maximum number of inboxes to return. |
| 14 | + last_key: The last key returned from the previous page. |
| 15 | +
|
| 16 | + Returns: |
| 17 | + A list of inboxes. |
| 18 | + """ |
| 19 | + return client.inboxes.list(limit=limit, last_key=last_key) |
| 20 | + |
| 21 | + |
| 22 | +def get_inbox(inbox_id: str): |
| 23 | + """ |
| 24 | + Get an inbox by ID. |
| 25 | +
|
| 26 | + Args: |
| 27 | + inbox_id: The ID of the inbox to get. |
| 28 | +
|
| 29 | + Returns: |
| 30 | + An inbox. |
| 31 | + """ |
| 32 | + return client.inboxes.get(inbox_id) |
| 33 | + |
| 34 | + |
| 35 | +def create_inbox( |
| 36 | + username: Optional[str] = None, |
| 37 | + domain: Optional[str] = None, |
| 38 | + display_name: Optional[str] = None, |
| 39 | +): |
| 40 | + """ |
| 41 | + Create an inbox. |
| 42 | +
|
| 43 | + Args: |
| 44 | + username: The username of the inbox. |
| 45 | + domain: The domain of the inbox. |
| 46 | + display_name: The display name of the inbox. |
| 47 | +
|
| 48 | + Returns: |
| 49 | + An inbox. |
| 50 | + """ |
| 51 | + return client.inboxes.create( |
| 52 | + username=username, domain=domain, display_name=display_name |
| 53 | + ) |
| 54 | + |
| 55 | + |
| 56 | +def list_threads( |
| 57 | + inbox_id: str, limit: Optional[int] = None, last_key: Optional[str] = None |
| 58 | +): |
| 59 | + """ |
| 60 | + List threads in an inbox. |
| 61 | +
|
| 62 | + Args: |
| 63 | + inbox_id: The ID of the inbox to list threads for. |
| 64 | + limit: The maximum number of threads to return. |
| 65 | + last_key: The last key returned from the previous page. |
| 66 | +
|
| 67 | + Returns: |
| 68 | + A list of threads. |
| 69 | + """ |
| 70 | + return client.threads.list(inbox_id=inbox_id, limit=limit, last_key=last_key) |
| 71 | + |
| 72 | + |
| 73 | +def get_thread(inbox_id: str, thread_id: str): |
| 74 | + """ |
| 75 | + Get a thread by ID. |
| 76 | +
|
| 77 | + Args: |
| 78 | + inbox_id: The ID of the inbox to get the thread for. |
| 79 | + thread_id: The ID of the thread to get. |
| 80 | +
|
| 81 | + Returns: |
| 82 | + A thread. |
| 83 | + """ |
| 84 | + return client.threads.get(inbox_id=inbox_id, thread_id=thread_id) |
| 85 | + |
| 86 | + |
| 87 | +def list_messages( |
| 88 | + inbox_id: str, limit: Optional[int] = None, last_key: Optional[str] = None |
| 89 | +): |
| 90 | + """ |
| 91 | + List messages in an inbox. |
| 92 | +
|
| 93 | + Args: |
| 94 | + inbox_id: The ID of the inbox to list messages for. |
| 95 | + limit: The maximum number of messages to return. |
| 96 | + last_key: The last key returned from the previous page. |
| 97 | +
|
| 98 | + Returns: |
| 99 | + A list of messages. |
| 100 | + """ |
| 101 | + return client.messages.list(inbox_id=inbox_id, limit=limit, last_key=last_key) |
| 102 | + |
| 103 | + |
| 104 | +def get_message(inbox_id: str, message_id: str): |
| 105 | + """ |
| 106 | + Get a message by ID. |
| 107 | +
|
| 108 | + Args: |
| 109 | + inbox_id: The ID of the inbox to get the message for. |
| 110 | + message_id: The ID of the message to get. |
| 111 | +
|
| 112 | + Returns: |
| 113 | + A message. |
| 114 | + """ |
| 115 | + return client.messages.get(inbox_id=inbox_id, message_id=message_id) |
| 116 | + |
| 117 | + |
| 118 | +def get_attachment(inbox_id: str, message_id: str, attachment_id: str): |
| 119 | + """ |
| 120 | + Get an attachment by message ID and attachment ID. |
| 121 | +
|
| 122 | + Args: |
| 123 | + inbox_id: The ID of the inbox to get the attachment for. |
| 124 | + message_id: The ID of the message to get the attachment for. |
| 125 | + attachment_id: The ID of the attachment to get. |
| 126 | +
|
| 127 | + Returns: |
| 128 | + An attachment. |
| 129 | + """ |
| 130 | + return client.messages.get_attachment( |
| 131 | + inbox_id=inbox_id, message_id=message_id, attachment_id=attachment_id |
| 132 | + ) |
| 133 | + |
| 134 | + |
| 135 | +def send_message( |
| 136 | + inbox_id: str, |
| 137 | + to: List[str], |
| 138 | + cc: Optional[List[str]] = None, |
| 139 | + bcc: Optional[List[str]] = None, |
| 140 | + subject: Optional[str] = None, |
| 141 | + text: Optional[str] = None, |
| 142 | + html: Optional[str] = None, |
| 143 | +): |
| 144 | + """ |
| 145 | + Send a message. |
| 146 | +
|
| 147 | + Args: |
| 148 | + inbox_id: The ID of the inbox to send the message from. |
| 149 | + to: The list of recipients. |
| 150 | + cc: The list of CC recipients. |
| 151 | + bcc: The list of BCC recipients. |
| 152 | + subject: The subject of the message. |
| 153 | + text: The plain text body of the message. |
| 154 | + html: The HTML body of the message. |
| 155 | +
|
| 156 | + Returns: |
| 157 | + A message. |
| 158 | + """ |
| 159 | + return client.messages.send( |
| 160 | + inbox_id=inbox_id, to=to, cc=cc, bcc=bcc, subject=subject, text=text, html=html |
| 161 | + ) |
| 162 | + |
| 163 | + |
| 164 | +def reply_to_message( |
| 165 | + inbox_id: str, |
| 166 | + message_id: str, |
| 167 | + text: Optional[str] = None, |
| 168 | + html: Optional[str] = None, |
| 169 | +): |
| 170 | + """ |
| 171 | + Reply to a message. |
| 172 | +
|
| 173 | + Args: |
| 174 | + inbox_id: The ID of the inbox to reply to the message in. |
| 175 | + message_id: The ID of the message to reply to. |
| 176 | + text: The plain text body of the reply. |
| 177 | + html: The HTML body of the reply. |
| 178 | +
|
| 179 | + Returns: |
| 180 | + A message. |
| 181 | + """ |
| 182 | + return client.messages.reply( |
| 183 | + inbox_id=inbox_id, message_id=message_id, text=text, html=html |
| 184 | + ) |
0 commit comments