Bindambc / whatsapp-business-java-api

Whatsapp business api SDK, written in java. This SDK implements the Official Whatsapp Cloud API and WhatsApp Business Management API. These allows you to: manage your WhatsApp Business Account assets, such as message templates and phone numbers; send messages to your contacts, such as simple text messages, messages with buttons...
https://bindambc.github.io/whatsapp-business-java-api/
MIT License
137 stars 69 forks source link

Unable to debug request and response header #82

Open tmoreira2020 opened 1 year ago

tmoreira2020 commented 1 year ago

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[bot] commented 1 year ago

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 commented 1 year ago

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:

        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

        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);

See also media object and Media

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