Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to debug request and response header #82

Open
tmoreira2020 opened this issue Apr 8, 2023 · 2 comments
Open

Unable to debug request and response header #82

tmoreira2020 opened this issue Apr 8, 2023 · 2 comments
Labels
question Further information is requested

Comments

@tmoreira2020
Copy link
Collaborator

Hey Maurício, first of all congrats in building such easy to use API. I've been looking for it for years! 😄

I'm still on testing phase and one things that I'm having hard time it to send ImageMessages to my phone number using the test number provided by Facebook. I will figured out what is going on but it will be much easier if I could turn on and off debug modes.

I have it working locally in a hackie way, once I have time I will send you a PR with the required changes.

Obrigado

@github-actions
Copy link

github-actions bot commented Apr 8, 2023

Hello and welcome! We're glad to see that you've opened your first issue. We appreciate your contribution and would love to hear more about the problem you're experiencing. Our team is actively monitoring this repository and we will do our best to respond to your issue as soon as possible. Thank you for using our project and we look forward to working with you!

@Bindambc
Copy link
Owner

Hello @tmoreira2020 ,

I'm glad that you're using this SDK. I'm looking for a way to create a log for API requests. If you have any suggestions, I would appreciate it.

Regarding image sending, here's a brief tutorial:
There are 3 ways to send an image through the WhatsApp Business API:

  • Uploading an image and then sending the message with the ID of that image:
        WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TOKEN);
        WhatsappBusinessCloudApi whatsappBusinessCloudApi = factory.newBusinessCloudApi();

        var fileName = "starwars.png";
        // reading the image
        byte[] fileContent = Files.readAllBytes(Paths.get("src/test/resources/" + fileName));

        //uploading to whatsapp api
        var uploadResponse = whatsappBusinessCloudApi.uploadMedia(PHONE_NUMBER_ID, fileName, FileType.PNG, fileContent);

        System.out.println(uploadResponse);

        //sending the message with the image id returned after upload
        var imageMessage = new ImageMessage()//
                .setId(uploadResponse.id())// media id (uploaded before)
                .setCaption("See this image, please");

        var message = MessageBuilder.builder()//
                .setTo(PHONE_NUMBER_1)//
                .buildImageMessage(imageMessage);

        MessageResponse messageResponse = whatsappBusinessCloudApi.sendMessage(PHONE_NUMBER_ID, message);

        System.out.println(messageResponse);

image

  • Sending a web link that points directly to the image.
        WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TOKEN);

        WhatsappBusinessCloudApi whatsappBusinessCloudApi = factory.newBusinessCloudApi();

        var imageMessage = new ImageMessage()//
                .setLink("https://upload.wikimedia.org/wikipedia/pt/4/45/Yoda.jpg").setCaption("See this image, please");

        var message = MessageBuilder.builder()//
                .setTo(PHONE_NUMBER_1)//
                .buildImageMessage(imageMessage);

        MessageResponse messageResponse = whatsappBusinessCloudApi.sendMessage(PHONE_NUMBER_ID, message);

        System.out.println(messageResponse);
  • Sending via Message Template. Message templates are required when your business is responsible for initiating the first interaction with the customer. Within a 24-hour period from the customer's first interaction, you don't need to use a template. However, if it's been more than 24 hours, you will need a template.

See also media object and Media

If you have any questions, please comment on this issue.

@Bindambc Bindambc added the question Further information is requested label Apr 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants