use of co.aurasphere.botmill.fb.model.base.Payload in project fb-botmill by BotMill.
the class TestDeserialization method main.
/**
* The main method.
*
* @param args the arguments
*/
public static void main(String[] args) {
String json = "{\"sender\":{\"id\":\"USER_ID\"},\"recipient\":{\"id\":\"PAGE_ID\"},\"timestamp\":1458692752478,\"message\":{\"mid\":\"mid.1458696618141:b4ef9d19ec21086067\",\"seq\":51,\"attachments\":[{\"type\":\"image\",\"payload\":{\"url\":\"IMAGE_URL\"}}]}}";
String json2 = "{\"sender\":{\"id\":\"1152902104831488\"},\"recipient\":{\"id\":\"1209810882431614\"},\"timestamp\":1482953812997,\"message\":{\"mid\":\"mid.1482953812997:6c6e910961\",\"seq\":778909,\"attachments\":[{\"title\":\"Alvin's Location\",\"url\":\"https:\\/\\/www.facebook.com\\/l.php?u=https%3A%2F%2Fwww.bing.com%2Fmaps%2Fdefault.aspx%3Fv%3D2%26pc%3DFACEBK%26mid%3D8100%26where1%3D43.899746%252C%2B-79.269825%26FORM%3DFBKPL1%26mkt%3Den-US&h=ATNzUb8qaIa5x61TRftUfE7RxWJE_E-5XeshoVeDOeGprLWnutTFxlENgC7vFhYuD3pB02N6PpzsEgcOiofJShlqT7a-lesSHScIzrLQVGPg-_22e6CETCbNhXeo57KTKsXLQU8&s=1&enc=AZNukLEVHCKFse_g9I7aBKSSgHbB3odYCw_9Do4rhrUXbJvjz_okfOP0gGwjSJ9Cd5PRpkxhT9kiCBrGBbXQCqPejz98NXzD6V6WVIEB4ZaDqA\",\"type\":\"location\",\"payload\":{\"coordinates\":{\"lat\":43.899746,\"long\":-79.269825}}}]}}";
MessageEnvelope envelope = FbBotMillJsonUtils.fromJson(json, MessageEnvelope.class);
Payload payload = envelope.getMessage().getAttachments().get(0).getPayload();
UrlPayload actualPayload = (UrlPayload) payload;
System.out.println(actualPayload.getUrl());
}
use of co.aurasphere.botmill.fb.model.base.Payload in project fb-botmill by BotMill.
the class AttachmentDeserializer method deserialize.
/*
* (non-Javadoc)
*
* @see
* com.google.gson.JsonDeserializer#deserialize(com.google.gson.JsonElement,
* java.lang.reflect.Type, com.google.gson.JsonDeserializationContext)
*/
public Attachment deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
Attachment attachment = delegateGson.fromJson(json, Attachment.class);
AttachmentType type = attachment.getType();
Class<? extends Payload> payloadClass = null;
JsonElement payloadJson = json.getAsJsonObject().get("payload");
switch(type) {
case AUDIO:
case FILE:
case IMAGE:
case VIDEO:
payloadClass = UrlPayload.class;
break;
case LOCATION:
payloadClass = QuickReplyLocationPayload.class;
break;
case FALLBACK:
// nothing.
break;
case TEMPLATE:
// In case of a template I need to check which one to instantiate.
String payloadTypeString = payloadJson.getAsJsonObject().get("template_type").getAsString();
PayloadType templateType = PayloadType.valueOf(payloadTypeString.toUpperCase());
switch(templateType) {
case AIRLINE_BOARDINGPASS:
payloadClass = AirlineBoardingPassTemplatePayload.class;
break;
case AIRLINE_CHECKIN:
payloadClass = AirlineCheckinTemplatePayload.class;
break;
case AIRLINE_ITINERARY:
payloadClass = AirlineItineraryTemplatePayload.class;
break;
case AIRLINE_UPDATE:
payloadClass = AirlineFlightUpdateTemplatePayload.class;
break;
case BUTTON:
payloadClass = ButtonTemplatePayload.class;
break;
case GENERIC:
payloadClass = GenericTemplatePayload.class;
break;
case LIST:
payloadClass = ListTemplatePayload.class;
break;
case RECEIPT:
payloadClass = ReceiptTemplatePayload.class;
break;
}
break;
}
Payload payload = context.deserialize(payloadJson, payloadClass);
attachment.setPayload(payload);
return attachment;
}
Aggregations