/**
* Send Message Tool
* Sends messages to various platforms via OpenClaw
*/
import type { OpenClawClient } from '../openclaw-client.js';
import type { SendMessageParams } from '../types.js';
/**
* Input schema for send_message tool
*/
export const SendMessageInputSchema = {
type: 'object',
properties: {
platform: {
type: 'string',
enum: ['telegram', 'whatsapp', 'discord'],
description: 'Target messaging platform',
},
recipient: {
type: 'string',
description: 'Recipient ID or username (e.g., @username for Telegram, phone number for WhatsApp)',
},
message: {
type: 'string',
description: 'Message content to send',
},
},
required: ['platform', 'recipient', 'message'],
};
/**
* Execute the send_message tool
*/
export async function executeSendMessage(
client: OpenClawClient,
args: SendMessageParams
) {
try {
// Validate inputs
if (!args.platform) {
return {
content: [
{
type: 'text',
text: JSON.stringify({ error: 'Platform is required' }, null, 2),
},
],
isError: true,
};
}
if (!args.recipient) {
return {
content: [
{
type: 'text',
text: JSON.stringify({ error: 'Recipient is required' }, null, 2),
},
],
isError: true,
};
}
if (!args.message || args.message.trim() === '') {
return {
content: [
{
type: 'text',
text: JSON.stringify({ error: 'Message content is required' }, null, 2),
},
],
isError: true,
};
}
// Call the OpenClaw API
const response = await client.sendMessage({
platform: args.platform,
recipient: args.recipient,
message: args.message,
});
if (response.success) {
return {
content: [
{
type: 'text',
text: JSON.stringify(
{
success: true,
platform: args.platform,
recipient: args.recipient,
messageId: response.messageId,
message: 'Message sent successfully',
},
null,
2
),
},
],
};
} else {
return {
content: [
{
type: 'text',
text: JSON.stringify(
{
success: false,
platform: args.platform,
recipient: args.recipient,
error: response.error || 'Failed to send message',
},
null,
2
),
},
],
isError: true,
};
}
} catch (error) {
return {
content: [
{
type: 'text',
text: JSON.stringify(
{
error: 'Unexpected error occurred',
details: error instanceof Error ? error.message : String(error),
},
null,
2
),
},
],
isError: true,
};
}
}
/**
* Tool definition for send_message
*/
export const SendMessageTool = {
name: 'send_message',
description: 'Send a message to a specified platform (Telegram, WhatsApp, or Discord) via OpenClaw',
inputSchema: SendMessageInputSchema,
};