Search in sources :

Example 1 with PayloadType

use of co.aurasphere.botmill.fb.model.outcoming.payload.PayloadType 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;
}
Also used : AttachmentType(co.aurasphere.botmill.fb.model.base.AttachmentType) JsonElement(com.google.gson.JsonElement) Attachment(co.aurasphere.botmill.fb.model.base.Attachment) Payload(co.aurasphere.botmill.fb.model.base.Payload) UrlPayload(co.aurasphere.botmill.fb.model.outcoming.payload.UrlPayload) QuickReplyLocationPayload(co.aurasphere.botmill.fb.model.base.QuickReplyLocationPayload) AirlineCheckinTemplatePayload(co.aurasphere.botmill.fb.model.outcoming.payload.template.airline.AirlineCheckinTemplatePayload) AirlineFlightUpdateTemplatePayload(co.aurasphere.botmill.fb.model.outcoming.payload.template.airline.AirlineFlightUpdateTemplatePayload) GenericTemplatePayload(co.aurasphere.botmill.fb.model.outcoming.payload.template.GenericTemplatePayload) ReceiptTemplatePayload(co.aurasphere.botmill.fb.model.outcoming.payload.template.ReceiptTemplatePayload) AirlineBoardingPassTemplatePayload(co.aurasphere.botmill.fb.model.outcoming.payload.template.airline.AirlineBoardingPassTemplatePayload) ListTemplatePayload(co.aurasphere.botmill.fb.model.outcoming.payload.template.ListTemplatePayload) ButtonTemplatePayload(co.aurasphere.botmill.fb.model.outcoming.payload.template.ButtonTemplatePayload) AirlineItineraryTemplatePayload(co.aurasphere.botmill.fb.model.outcoming.payload.template.airline.AirlineItineraryTemplatePayload) PayloadType(co.aurasphere.botmill.fb.model.outcoming.payload.PayloadType)

Aggregations

Attachment (co.aurasphere.botmill.fb.model.base.Attachment)1 AttachmentType (co.aurasphere.botmill.fb.model.base.AttachmentType)1 Payload (co.aurasphere.botmill.fb.model.base.Payload)1 QuickReplyLocationPayload (co.aurasphere.botmill.fb.model.base.QuickReplyLocationPayload)1 PayloadType (co.aurasphere.botmill.fb.model.outcoming.payload.PayloadType)1 UrlPayload (co.aurasphere.botmill.fb.model.outcoming.payload.UrlPayload)1 ButtonTemplatePayload (co.aurasphere.botmill.fb.model.outcoming.payload.template.ButtonTemplatePayload)1 GenericTemplatePayload (co.aurasphere.botmill.fb.model.outcoming.payload.template.GenericTemplatePayload)1 ListTemplatePayload (co.aurasphere.botmill.fb.model.outcoming.payload.template.ListTemplatePayload)1 ReceiptTemplatePayload (co.aurasphere.botmill.fb.model.outcoming.payload.template.ReceiptTemplatePayload)1 AirlineBoardingPassTemplatePayload (co.aurasphere.botmill.fb.model.outcoming.payload.template.airline.AirlineBoardingPassTemplatePayload)1 AirlineCheckinTemplatePayload (co.aurasphere.botmill.fb.model.outcoming.payload.template.airline.AirlineCheckinTemplatePayload)1 AirlineFlightUpdateTemplatePayload (co.aurasphere.botmill.fb.model.outcoming.payload.template.airline.AirlineFlightUpdateTemplatePayload)1 AirlineItineraryTemplatePayload (co.aurasphere.botmill.fb.model.outcoming.payload.template.airline.AirlineItineraryTemplatePayload)1 JsonElement (com.google.gson.JsonElement)1