11import { z } from 'zod' ;
2- import { SirenClient , ProviderCode } from '@trysiren/node' ;
2+ import { SirenClient , ProviderCode , RecipientChannel } from '@trysiren/node' ;
33import { Context } from '../configuration' ;
44import type { Tool } from '../tools' ;
55
66const sendMessageSchema = z . object ( {
7- recipient_value : z . string ( ) . describe ( 'Identifier for the recipient (e.g., Slack user ID, email address)' ) ,
8- channel : z . string ( ) . describe ( 'The channel to send the message through (e.g., "SLACK", "EMAIL")' ) ,
9- body : z . string ( ) . optional ( ) . describe ( 'Message body text (required if no template)' ) ,
10- template_name : z . string ( ) . optional ( ) . describe ( 'Template name (required if no body)' ) ,
11- template_variables : z . record ( z . any ( ) ) . optional ( ) . describe ( 'Template variables for template-based messages' ) ,
7+ recipient_value : z
8+ . string ( )
9+ . describe (
10+ 'Identifier for the recipient (e.g., Slack user ID, email address)'
11+ ) ,
12+ channel : z
13+ . nativeEnum ( RecipientChannel )
14+ . describe (
15+ 'The channel to send the message through (e.g., "SLACK", "EMAIL")'
16+ ) ,
17+ body : z
18+ . string ( )
19+ . optional ( )
20+ . describe ( 'Message body text (required if no template)' ) ,
21+ subject : z
22+ . string ( )
23+ . optional ( )
24+ . describe (
25+ 'Subject line for the message (optional, required for email with body)'
26+ ) ,
27+ template_name : z
28+ . string ( )
29+ . optional ( )
30+ . describe ( 'Template name (required if no body)' ) ,
31+ template_variables : z
32+ . record ( z . any ( ) )
33+ . optional ( )
34+ . describe ( 'Template variables for template-based messages' ) ,
1235 provider_name : z . string ( ) . optional ( ) . describe ( 'Provider integration name' ) ,
13- provider_code : z . nativeEnum ( ProviderCode ) . optional ( ) . describe ( 'Provider integration code' ) ,
36+ provider_code : z
37+ . nativeEnum ( ProviderCode )
38+ . optional ( )
39+ . describe ( 'Provider integration code' ) ,
1440} ) ;
1541
1642export const sendMessage = async (
@@ -19,30 +45,33 @@ export const sendMessage = async (
1945 params : z . infer < typeof sendMessageSchema >
2046) => {
2147 try {
22- const notificationId = await sirenClient . message . send (
23- params . recipient_value ,
24- params . channel ,
25- params . body ,
26- params . template_name ,
27- params . template_variables ,
28- params . provider_name ,
29- params . provider_code
30- ) ;
31-
48+ const messagePayload = {
49+ recipientValue : params . recipient_value ,
50+ channel : params . channel ,
51+ body : params . body ,
52+ subject : params . subject ,
53+ templateName : params . template_name ,
54+ templateVariables : params . template_variables ,
55+ providerName : params . provider_name ,
56+ providerCode : params . provider_code ,
57+ } ;
58+ const notificationId = await sirenClient . message . send ( messagePayload ) ;
59+
3260 return { notificationId } ;
3361 } catch ( error ) {
3462 console . error ( 'Failed to send message:' , error ) ;
3563 return {
3664 error : 'Failed to send message' ,
37- details : error instanceof Error ? error . message : String ( error )
65+ details : error instanceof Error ? error . message : String ( error ) ,
3866 } ;
3967 }
4068} ;
4169
4270const tool = ( context : Context ) : Tool => ( {
4371 method : 'send_message' ,
4472 name : 'Send Message' ,
45- description : 'Send a message either using a template or directly to a recipient via a chosen channel' ,
73+ description :
74+ 'Send a message either using a template or directly to a recipient via a chosen channel' ,
4675 parameters : sendMessageSchema ,
4776 actions : {
4877 messaging : {
@@ -52,4 +81,4 @@ const tool = (context: Context): Tool => ({
5281 execute : sendMessage ,
5382} ) ;
5483
55- export default tool ;
84+ export default tool ;
0 commit comments