-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Expand file tree
/
Copy pathforward_message.ts
More file actions
112 lines (105 loc) · 3.1 KB
/
Copy pathforward_message.ts
File metadata and controls
112 lines (105 loc) · 3.1 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
100
101
102
103
104
105
106
107
108
109
110
111
112
import type { ForwardMessageParams, ForwardMessageResult } from '@/tools/agentmail/types'
import type { ToolConfig } from '@/tools/types'
export const agentmailForwardMessageTool: ToolConfig<ForwardMessageParams, ForwardMessageResult> = {
id: 'agentmail_forward_message',
name: 'Forward Message',
description: 'Forward an email message to new recipients in AgentMail',
version: '1.0.0',
params: {
apiKey: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'AgentMail API key',
},
inboxId: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'ID of the inbox containing the message',
},
messageId: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'ID of the message to forward',
},
to: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'Recipient email addresses (comma-separated)',
},
subject: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Override subject line',
},
text: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Additional plain text to prepend',
},
html: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Additional HTML to prepend',
},
cc: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'CC recipient email addresses (comma-separated)',
},
bcc: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'BCC recipient email addresses (comma-separated)',
},
},
request: {
url: (params) =>
`https://api.agentmail.to/v0/inboxes/${params.inboxId.trim()}/messages/${params.messageId.trim()}/forward`,
method: 'POST',
headers: (params) => ({
Authorization: `Bearer ${params.apiKey}`,
'Content-Type': 'application/json',
}),
body: (params) => {
const body: Record<string, unknown> = {
to: params.to.split(',').map((e) => e.trim()),
}
if (params.subject) body.subject = params.subject
if (params.text) body.text = params.text
if (params.html) body.html = params.html
if (params.cc) body.cc = params.cc.split(',').map((e) => e.trim())
if (params.bcc) body.bcc = params.bcc.split(',').map((e) => e.trim())
return body
},
},
transformResponse: async (response): Promise<ForwardMessageResult> => {
const data = await response.json()
if (!response.ok) {
return {
success: false,
error: data.message ?? 'Failed to forward message',
output: { messageId: '', threadId: '' },
}
}
return {
success: true,
output: {
messageId: data.message_id ?? '',
threadId: data.thread_id ?? '',
},
}
},
outputs: {
messageId: { type: 'string', description: 'ID of the forwarded message' },
threadId: { type: 'string', description: 'ID of the thread' },
},
}