whatsapp-business-java-api
whatsapp-business-java-api copied to clipboard
Unable to debug request and response header
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
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!
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);
- 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.