Skip to content

Comments

[Tool] add send media message images#11

Merged
pnizer merged 13 commits intopnizer:mainfrom
ayokanme:tool/add-send-media-message-images
Apr 12, 2025
Merged

[Tool] add send media message images#11
pnizer merged 13 commits intopnizer:mainfrom
ayokanme:tool/add-send-media-message-images

Conversation

@ayokanme
Copy link
Contributor

This change extends the existing functionality by adding the ability to send media messages (images only for now)

Changes:

  • updates to Dockerfile to copy over tsconfig.json and package.jsonfiles before runningnpm install`
  • linting changes to remove extra white spaces
  • add /send_media endpoint to api
  • add sendMediaMessage method to whatsapp api client and service
  • register the server tool
  • added tests (mocked whatsapp web client in whatsapp-service.test.ts to test newly added method)
  • updated readme

Copy link
Owner

@pnizer pnizer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @ayokanme for your contributions. I added some feedbacks on your PR.

if (mediaType === 'url') {
media = await MessageMedia.fromUrl(mediaLocation);
} else {
media = await MessageMedia.fromFilePath(mediaLocation);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to add a way to restrict the access files only from allowed paths

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed with new commits

src/types.ts Outdated

export interface SendMediaMessageParams {
number: string;
mediaType: 'url' | 'local';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if instead of adding media type as params, we decide that by the location: if location starts with http:// or https:// its url, if it starts with file:// its local?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good suggestion. implemented and removed the mediaType param, renamed mediaLocation to source

I'll make a follow on PR to video and voice note support

number: z.string().describe('The phone number to send the message to'),
mediaType: z.enum(['url', 'local']).describe('Whether the media is from a URL or local file'),
mediaLocation: z.string().describe('The URL or local file path of the image'),
caption: z.string().optional().describe('Optional caption for the image'),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of limitations on OpenAI response API, that doesn't support optional fields on tools for now, we need to remove the optional() or add a configuration that disable all optional fields

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is support for this. You can specify required properties. But updated to default to '' when not passed in

@ayokanme ayokanme requested a review from pnizer April 6, 2025 01:27
@pnizer pnizer merged commit 560b2b0 into pnizer:main Apr 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants