Skip to content

Commit 9d931d6

Browse files
committed
build: v.0.1.14
1 parent 4b67d4b commit 9d931d6

4 files changed

Lines changed: 156 additions & 1 deletion

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pam-react-native",
3-
"version": "0.1.13",
3+
"version": "0.1.14",
44
"description": "Pam SDK for React Native",
55
"source": "./src/index.tsx",
66
"main": "./lib/commonjs/index.js",

src/api.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { ConsentMessage } from './interface/consent_message';
77
import type { IAttentionItem } from './interface/attention';
88
import type { ICustomerConsentStatus } from './interface/iconsent_status';
99
import { Utils } from './utils';
10+
import type { PamPushMessage } from './interface/pam_push_message';
11+
1012
export class PamAPI {
1113
private http: HTTPClient;
1214

@@ -163,4 +165,53 @@ export class PamAPI {
163165

164166
return result;
165167
}
168+
169+
async loadPushNotificationsFromCustomerID(
170+
database: string,
171+
contactID: string,
172+
customer: string
173+
): Promise<PamPushMessage[] | null> {
174+
let response: any;
175+
try {
176+
const url = `/api/app-notifications?_database=${database}&_contact_id=${contactID}&customer=${customer}`;
177+
response = await this.http.get(url, {});
178+
} catch (e) {}
179+
if (response) {
180+
return response.data as PamPushMessage[];
181+
}
182+
return null;
183+
}
184+
185+
async loadPushNotificationsFromMobile(
186+
database: string,
187+
contactID: string,
188+
mobileNumber: string
189+
): Promise<PamPushMessage[] | null> {
190+
let response: any;
191+
try {
192+
const url = `/api/app-notifications?_database=${database}&_contact_id=${contactID}&sms=${mobileNumber}`;
193+
response = await this.http.get(url, {});
194+
} catch (e) {}
195+
196+
if (response) {
197+
return response.data as PamPushMessage[];
198+
}
199+
return null;
200+
}
201+
202+
async loadPushNotificationsFromEmail(
203+
database: string,
204+
contactID: string,
205+
email: string
206+
): Promise<PamPushMessage[] | null> {
207+
let response: any;
208+
try {
209+
const url = `/api/app-notifications?_database=${database}&_contact_id=${contactID}&email=${email}`;
210+
response = await this.http.get(url, {});
211+
} catch (e) {}
212+
if (response) {
213+
return response.data as PamPushMessage[];
214+
}
215+
return null;
216+
}
166217
}

src/index.tsx

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import PamTracker from './PamTracker';
66
import type { ConsentMessage } from './interface/consent_message';
77
import { type AppAttentionStyle } from './interface/app_attention_style';
88
import { Linking } from 'react-native';
9+
import type { PamPushMessage } from './interface/pam_push_message';
910

1011
const LINKING_ERROR =
1112
`The package 'pam-react-native' doesn't seem to be linked. Make sure: \n\n` +
@@ -130,6 +131,96 @@ export class Pam {
130131
}
131132
}
132133

134+
static isPushNotiFromPam(message: any) {
135+
return message.data.hasOwnProperty('pam');
136+
}
137+
138+
static convertToPamPushMessage(message: any): PamPushMessage | undefined {
139+
if (Pam.isPushNotiFromPam(message)) {
140+
let data = message.data;
141+
let pam: any = data.pam;
142+
let payload: Record<string, any>;
143+
144+
try {
145+
payload = JSON.parse(pam);
146+
} catch (e) {
147+
return undefined;
148+
}
149+
150+
const flex = payload.flex;
151+
const regExp = /src="(.*?)"/;
152+
const match = flex.match(regExp);
153+
const banner = match?.[1] ?? '';
154+
const pixel = payload.pixel ?? '';
155+
const popupType = payload.popup_type ?? '';
156+
const url = payload.url;
157+
const title = message.notification?.title ?? '';
158+
const description = message.notification?.body ?? '';
159+
160+
var item = {
161+
deliverID: '',
162+
pixel: pixel,
163+
title: title,
164+
description: description,
165+
thumbnailUrl: banner,
166+
flex: flex,
167+
url: url,
168+
popupType: popupType,
169+
date: new Date(),
170+
isOpen: false,
171+
data: payload,
172+
};
173+
174+
return item;
175+
}
176+
return undefined;
177+
}
178+
179+
static async loadPushNotificationsFromCustomerID(
180+
customerID: string
181+
): Promise<PamPushMessage[] | null> {
182+
const contactID = Pam.shared?.contactState?.getContactId();
183+
const database = Pam.shared?.contactState?.getDatabase();
184+
if (!contactID || !database) {
185+
return null;
186+
}
187+
return await Pam.pamApi.loadPushNotificationsFromCustomerID(
188+
database,
189+
contactID,
190+
customerID
191+
);
192+
}
193+
194+
static async loadPushNotificationsFromMobile(
195+
mobileNumber: string
196+
): Promise<PamPushMessage[] | null> {
197+
const contactID = Pam.shared?.contactState?.getContactId();
198+
const database = Pam.shared?.contactState?.getDatabase();
199+
if (!contactID || !database) {
200+
return null;
201+
}
202+
return await Pam.pamApi.loadPushNotificationsFromMobile(
203+
database,
204+
contactID,
205+
mobileNumber
206+
);
207+
}
208+
209+
static async loadPushNotificationsFromEmail(
210+
email: string
211+
): Promise<PamPushMessage[] | null> {
212+
const contactID = Pam.shared?.contactState?.getContactId();
213+
const database = Pam.shared?.contactState?.getDatabase();
214+
if (!contactID || !database) {
215+
return null;
216+
}
217+
return await Pam.pamApi.loadPushNotificationsFromEmail(
218+
database,
219+
contactID,
220+
email
221+
);
222+
}
223+
133224
static async track(event: string, payload: Record<string, any>) {
134225
return await Pam.shared?.track(event, payload);
135226
}

src/interface/pam_push_message.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export interface PamPushMessage {
2+
deliverID?: string;
3+
pixel?: string;
4+
title?: string;
5+
description?: string;
6+
thumbnailUrl?: string;
7+
flex?: string;
8+
url?: string;
9+
popupType?: string;
10+
bisOpen?: boolean;
11+
date?: Date;
12+
data?: Record<string, any>;
13+
}

0 commit comments

Comments
 (0)