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
Can I send WhatsApp Business Platform Cloud API message using restfb #1225
Comments
As I see, the problem is the data. The publish methods we have so far, can only post form data. But we have no way so far to post a "simple" json. I think this should be one of the next steps before supporting all the objects. The access token in the header is not a problem and the |
As short update. I will use this issue to add a way to post a JSON as "body" to an endpoint as alternative to send the data in a form. This should solve the basic problem, and you can start (as soon as the release is published) using RestFB to send WhatsApp messages. The concept is ready so far, and I already started the implementation, but the unit tests are missing atm. Hopefully everything's ready after the weekend and this great feature will be available next week. Thanks for the input/question 😀 |
With the next release it will be possible using a code similar to this snippet: DefaultFacebookClient fbClient = new DefaultFacebookClient("<access token>", Version.VERSION_13_0);
fbClient.setHeaderAuthorization(true);
JsonObject message = new JsonObject();
// fill message JSON here - as long as we have no WABP objects in place
Body body = Body.withData(message);
JsonObject result = fbClient.publish("FROM_PHONE_NUMBER_ID/messages", JsonObject.class, body); |
I have to correct the code. DefaultFacebookClient fbClient = new DefaultFacebookClient(waAccessToken, Version.VERSION_13_0);
fbClient.setHeaderAuthorization(true);
JsonObject textJso = new JsonObject();
textJso.add("preview_url", false);
textJso.add("body", "this is a short test message");
Parameter[] params = new Parameter[] { //
Parameter.with("messaging_product", "whatsapp"), //
Parameter.with("recipient_type", "individual"), //
Parameter.with("type", "text"), //
Parameter.with("to", "<recipient number>"), //
Parameter.with("text", textJso)};
// Send the data and get the result as JsonObject
JsonObject jso = fbClient.publish(sendWaId + "/messages", JsonObject.class, params);
System.out.println(jso.toString()); |
With the latest fix on this issue, it is possible to post a json object direct as body. Using body looks like: DefaultFacebookClient fbClient = new DefaultFacebookClient(waAccessToken, Version.VERSION_13_0);
fbClient.setHeaderAuthorization(true);
JsonObject sJso = new JsonObject();
sJso.add("messaging_product", "whatsapp");
sJso.add("recipient_type", "individual");
sJso.add("type", "text");
sJso.add("to", "<recipient number>");
JsonObject textJso = new JsonObject();
textJso.add("preview_url", false);
textJso.add("body", "this is a short test message");
sJso.add("text", textJso);
// post json as body
JsonObject jso = fbClient.publish(sendWaId + "/messages", JsonObject.class, Body.withData(sJso));
System.out.println(jso.toString()); |
Thank you for fast response |
I see WABP integration is in upcoming todo. Currently can I send simple whatsapp Media Messages using restfb?
The text was updated successfully, but these errors were encountered: