Upload New File

parent 2fd19f3a
package com.bot;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
public class MessageSender {
private static final String ACCESS_TOKEN = "EAFYJZCF8GyacBOZBlxVNRwqZBNA4BJVYYCH9gKRk0fjdG1XaONKXQnDIqldZB8mvpNVpILnCuOsHyv81CBKa3pG9G6pRsEAxTI4FAUdFEBhlmsV22YdBs5svyKmFe4bcsuirk8wvPoTHTXTsCvqDZBLTwgmDSz9NZC9rfUBxSVTM37zZCcHZBZAm69duKjUxO56ZBAeOr4KdBUyJxUHx965TeBYSoKULRcTLXH3HcZD";
private static final String PHONE_NUMBER_ID = "647550301772780";
public static void sendTextMessage(String to, String messageBody) {
try {
URL url = new URL("https://graph.facebook.com/v19.0/" + PHONE_NUMBER_ID + "/messages");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Authorization", "Bearer " + ACCESS_TOKEN);
conn.setRequestProperty("Content-Type", "application/json");
conn.setDoOutput(true);
String json = String.format("{\n \"messaging_product\": \"whatsapp\",\n \"to\": \"%s\",\n \"text\": { \"body\": \"%s\" }\n}", to, messageBody);
OutputStream os = conn.getOutputStream();
os.write(json.getBytes());
os.flush();
os.close();
int code = conn.getResponseCode();
System.out.println("Response Code: " + code);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment