Skip to content

Commit

Permalink
Facebook buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
docwho2 committed Aug 5, 2024
1 parent 5bb964c commit 53e7640
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static cloud.cleo.squareup.ChatGPTLambda.mapper;
import static cloud.cleo.squareup.functions.PrivateShoppingLink.PRIVATE_SHOPPING_URL;
import java.math.BigDecimal;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
Expand Down Expand Up @@ -72,8 +73,9 @@ public static void transferToInbox(String id) {
* Send our private Shopping URL as a Messenger Button
*
* @param id of the recipient
* @return true if successfully sent
*/
public static void sendPrivateBookingURL(String id) {
public static boolean sendPrivateBookingURL(String id) {
HttpURLConnection connection = null;
try {
connection = (HttpURLConnection) getFaceBookURL(null, "me/messages").openConnection();
Expand All @@ -91,12 +93,13 @@ public static void sendPrivateBookingURL(String id) {
json.putObject("message").putObject("attachment")
.put("type", "template").putObject("payload")
.put("template_type", "button")
.put("text", "Book Private Shopping")
.put("text", "Book Your Private Shopping Experience")
.putArray("buttons")
.addObject()
.put("type", "web_url")
.put("messenger_extensions", true)
.put("url", "https://" + PRIVATE_SHOPPING_URL)
.put("title", "Book Private Shopping")
.put("title", "Book Now!")
.put("webview_height_ratio", "full");

log.debug("Post Payload for URL push" + json.toPrettyString());
Expand All @@ -110,6 +113,7 @@ public static void sendPrivateBookingURL(String id) {

if (result.findValue("message_id") != null) {
log.debug("Call Succeeded in sending URL in FB Messenger");
return true;
} else {
log.debug("Call FAILED to send URL in FB Messenger");
}
Expand All @@ -121,6 +125,7 @@ public static void sendPrivateBookingURL(String id) {
connection.disconnect();
}
}
return false;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ protected Function getExecutor() {
return (var r) -> {

if (getChannelPlatform().equals(FACEBOOK)) {
FaceBookOperations.sendPrivateBookingURL(getSessionId());
if ( FaceBookOperations.sendPrivateBookingURL(getSessionId()) ) {
return mapper.createObjectNode().put("message", "URL was just sent out of band successfully as a Messenger Button, so just make reference to the URL button above as part of your response");
}
}
return mapper.createObjectNode().put("url", PRIVATE_SHOPPING_URL);
};
Expand Down

0 comments on commit 53e7640

Please sign in to comment.