Payload Example

payload code examples per layout

payload Example

Following are payload examples per layout.

Note: For details on 'payload', refer to payload Structure.

personetics.startWidget({
    "configurations": {
        "deviceType": "web",
        "ctxId": "dashboard",
        "params": {
            "payload": {
                "GET_INSIGHTS": {
                    "ok": true,
                    "protocolVersion": "2.6",
                    "requestChannel": "VANILLA_QA",
                    "requestType": "getInsights",
                    "requestId": "NLjFSETDjW7-K35x",
                    "status": "200",
                    "statusMessage": "ok",
                    "insights": []],
                "numberOfInsights": 8,
                "unreadMessages": 4,
                "numberOfUnreadInsights": 4
            }
        },
        "userId": "B_1012"
    },
    "selectorString": "#root",
    "widgetType": "inbox"
},
"assets": {
  	"useRemoteAssets": false,
    "baseUrl": "https: //client-vanilla-assets.s3.amazonaws.com/product-react-assets/assets/"
},
"internationalization": {
    "language": "en"
},
})
func getPayloadForType(type: String, requestType: String, navParams: NSMutableDictionary?) {
        let serverUrl = NetworkManager.shared.getEngageServerUrl()
        let requestType = requestType
        let requestBodyParams = NSMutableDictionary.init()
        guard let constants = NetworkManager.shared.constants else { return }
 
        requestBodyParams.setValue(requestType, forKey: "type")
        requestBodyParams.setValue("dashboard", forKey: Personetics.PDBctxId)
        requestBodyParams.setValue(constants.protocolVersion, forKey: "protocolVersion")
        requestBodyParams.setValue(constants.appLanguage, forKey: "lang")
        let requestHeaders = NetworkManager.shared.getOptionalReqHeaders()
        NetworkManager.shared.doPostMessage(serverUrl: serverUrl, reqHttpBoday: requestBodyParams,
                                            reqHeaders: requestHeaders, requestType: requestType, onSuccess: { [weak self] result in
            if let payload = result as? String {
                switch type {
                case "story-widget":
                    self?.startStoryWidget(payload: BankUtility.stringToJsonObject(dataString: payload))
                case "recap":
                    self?.startRecapWidget(payload: BankUtility.stringToJsonObject(dataString: payload))
                case "inbox":
                    self?.startInboxWidget(payload: BankUtility.stringToJsonObject(dataString: payload))
                case "hub":
                    self?.startHubWidget(payload: BankUtility.stringToJsonObject(dataString: payload))
                case "singleTeaser":
                    self?.startSingleTeaserWidget(payload: BankUtility.stringToJsonObject(dataString: payload))
                case "singleTrackerTeaser":
                    self?.startSingleTrackerTeaserWidget(payload: BankUtility.stringToJsonObject(dataString: payload))
                case "trackersDashboard":
                    self?.startTrackersDashboardWidget(payload: BankUtility.stringToJsonObject(dataString: payload))
                case "carousel":
                    self?.startCarouselWidget(payload: BankUtility.stringToJsonObject(dataString: payload))
                case "manage-budgets":
                    if let addNavParams = navParams {
                        self?.startBudgetManageWidget(payload: BankUtility
                            .stringToJsonObject(dataString: payload), navParams: addNavParams)
                    } else {
                        self?.startBudgetManageWidget(payload: BankUtility
                            .stringToJsonObject(dataString: payload), navParams: nil)
                    }
                case "subscription-dashboard":
                    if let addNavParams = navParams {
                        self?.startSubscriptionDashboardWidget(payload: BankUtility
                            .stringToJsonObject(dataString: payload), navParams: addNavParams)
                    } else {
                        self?.startSubscriptionDashboardWidget(payload: BankUtility
                            .stringToJsonObject(dataString: payload), navParams: nil)
                    }
                case "actOnboarding":
                    if let addNavParams = navParams{
                        self?.startOnboardingWidget(payload: BankUtility.stringToJsonObject(dataString: payload), navParams: addNavParams)
                    }else{
                        self?.startOnboardingWidget(payload: BankUtility.stringToJsonObject(dataString: payload), navParams:nil)
                    }
                case "actManagement":
                    if let addNavParams = navParams{
                        self?.startManagementWidget(payload: BankUtility.stringToJsonObject(dataString: payload), navParams: addNavParams)
                    }else{
                        self?.startManagementWidget(payload: BankUtility.stringToJsonObject(dataString: payload), navParams:nil)
                    }
                default:
                    break
                }
            } else {
            }
        }, onError: {result in
            print("Get Payload \(requestType) Response ****Failed****: \(String(describing: result)))")
        })
    }

private View populatePersoneticsPriview() {
    JSONObject configurations = new JSONObject();
    JSONObject params = new JSONObject();
    JSONObject assets = new JSONObject();
    JSONObject internationalization = new JSONObject();
    JSONObject theme = new JSONObject();

    try {
        params.put(Personetics.PDB_USER_ID, getResources().getString(R.string.default_user));
        configurations.put(Personetics.PDB_WIDGET_TYPE, "inbox");
        configurations.put(Personetics.PDB_DEVICE_TYPE, "android");
        configurations.put(Personetics.PDB_SELECTOR_STRING, "#root");
        if(getResources().getBoolean(R.bool.is_use_remote_assets_mode)) {
            assets.put(Personetics.PDB_BASEURL, getString(R.string.remote_assets));
            assets.put(Personetics.PDB_USEREMOTEASSETS, true);
        }
        internationalization.put(Personetics.PDB_LANGUAGE, "en");
        theme.put(Personetics.PDB_DARKMODE, false);
        if (getResources().getBoolean(R.bool.is_use_payload)){
            params.put(Personetics.PDB_PAYLOAD,payload);
        }
        configurations.put(Personetics.PDB_PARAMS, params);
        config.put(Personetics.PDB_CONFIGURATIONS, configurations);
        config.put(Personetics.PDB_ASSETS, assets);
        config.put(Personetics.PDB_INTERNATIONALIZATION, internationalization);
        config.put(Personetics.PDB_THEME, theme);

    } catch (JSONException e) {
        e.printStackTrace();
    }
    return  ((MainActivity)getActivity()).getPersonetics().startWidgetWithView(getActivity(), config);
}

The payload variable contains:
payload.put("GET_INBOX_INSIGHTS",jsonResponse);