Skip to content

Commit d06285d

Browse files
committed
feat(Platform Notifications): include acknowledge endpoints
1 parent 4b249d7 commit d06285d

4 files changed

Lines changed: 406 additions & 118 deletions

File tree

examples/platform-notifications.v1.test.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,63 @@ describe('PlatformNotificationsV1', () => {
352352
// end-list_notifications
353353
});
354354

355+
test('getAcknowledgement request example', async () => {
356+
consoleLogMock.mockImplementation((output) => {
357+
originalLog(output);
358+
});
359+
consoleWarnMock.mockImplementation((output) => {
360+
// if an error occurs, display the message and then fail the test
361+
originalWarn(output);
362+
expect(true).toBeFalsy();
363+
});
364+
365+
originalLog('getAcknowledgement() result:');
366+
// begin-get_acknowledgement
367+
368+
const params = {
369+
accountId: '1369339417d906e5620b8d861d40cfd7',
370+
};
371+
372+
let res;
373+
try {
374+
res = await platformNotificationsService.getAcknowledgement(params);
375+
console.log(JSON.stringify(res.result, null, 2));
376+
} catch (err) {
377+
console.warn(err);
378+
}
379+
380+
// end-get_acknowledgement
381+
});
382+
383+
test('replaceNotificationAcknowledgement request example', async () => {
384+
consoleLogMock.mockImplementation((output) => {
385+
originalLog(output);
386+
});
387+
consoleWarnMock.mockImplementation((output) => {
388+
// if an error occurs, display the message and then fail the test
389+
originalWarn(output);
390+
expect(true).toBeFalsy();
391+
});
392+
393+
originalLog('replaceNotificationAcknowledgement() result:');
394+
// begin-replace_notification_acknowledgement
395+
396+
const params = {
397+
lastAcknowledgedId: '1772804159452',
398+
accountId: '1369339417d906e5620b8d861d40cfd7',
399+
};
400+
401+
let res;
402+
try {
403+
res = await platformNotificationsService.replaceNotificationAcknowledgement(params);
404+
console.log(JSON.stringify(res.result, null, 2));
405+
} catch (err) {
406+
console.warn(err);
407+
}
408+
409+
// end-replace_notification_acknowledgement
410+
});
411+
355412
test('deleteDistributionListDestination request example', async () => {
356413
consoleLogMock.mockImplementation((output) => {
357414
originalLog(output);

platform-notifications/v1.ts

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,125 @@ class PlatformNotificationsV1 extends BaseService {
926926

927927
return this.createRequest(parameters);
928928
}
929+
930+
/**
931+
* Get user's last acknowledged notification Id.
932+
*
933+
* Retrieve the ID of the last notification acknowledged by the user for a specific account.
934+
*
935+
* @param {Object} [params] - The parameters to send to the service.
936+
* @param {string} [params.accountId] - The account ID to retrieve acknowledgement for.
937+
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
938+
* @returns {Promise<PlatformNotificationsV1.Response<PlatformNotificationsV1.Acknowledgement>>}
939+
*/
940+
public getAcknowledgement(
941+
params?: PlatformNotificationsV1.GetAcknowledgementParams
942+
): Promise<PlatformNotificationsV1.Response<PlatformNotificationsV1.Acknowledgement>> {
943+
const _params = { ...params };
944+
const _requiredParams = [];
945+
const _validParams = ['accountId', 'signal', 'headers'];
946+
const _validationErrors = validateParams(_params, _requiredParams, _validParams);
947+
if (_validationErrors) {
948+
return Promise.reject(_validationErrors);
949+
}
950+
951+
const query = {
952+
'account_id': _params.accountId,
953+
};
954+
955+
const sdkHeaders = getSdkHeaders(
956+
PlatformNotificationsV1.DEFAULT_SERVICE_NAME,
957+
'v1',
958+
'getAcknowledgement'
959+
);
960+
961+
const parameters = {
962+
options: {
963+
url: '/v1/notifications/acknowledgement',
964+
method: 'GET',
965+
qs: query,
966+
},
967+
defaultOptions: extend(true, {}, this.baseOptions, {
968+
headers: extend(
969+
true,
970+
sdkHeaders,
971+
this.baseOptions.headers,
972+
{
973+
'Accept': 'application/json',
974+
},
975+
_params.headers
976+
),
977+
axiosOptions: {
978+
signal: _params.signal,
979+
},
980+
}),
981+
};
982+
983+
return this.createRequest(parameters);
984+
}
985+
986+
/**
987+
* Update user's last acknowledged notification.
988+
*
989+
* Update the ID of the last notification acknowledged by the user for a specific account.
990+
*
991+
* @param {Object} params - The parameters to send to the service.
992+
* @param {string} params.lastAcknowledgedId - The ID of a notification.
993+
* @param {string} [params.accountId] - The account ID to update acknowledgement for.
994+
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
995+
* @returns {Promise<PlatformNotificationsV1.Response<PlatformNotificationsV1.Acknowledgement>>}
996+
*/
997+
public replaceNotificationAcknowledgement(
998+
params: PlatformNotificationsV1.ReplaceNotificationAcknowledgementParams
999+
): Promise<PlatformNotificationsV1.Response<PlatformNotificationsV1.Acknowledgement>> {
1000+
const _params = { ...params };
1001+
const _requiredParams = ['lastAcknowledgedId'];
1002+
const _validParams = ['lastAcknowledgedId', 'accountId', 'signal', 'headers'];
1003+
const _validationErrors = validateParams(_params, _requiredParams, _validParams);
1004+
if (_validationErrors) {
1005+
return Promise.reject(_validationErrors);
1006+
}
1007+
1008+
const body = {
1009+
'last_acknowledged_id': _params.lastAcknowledgedId,
1010+
};
1011+
1012+
const query = {
1013+
'account_id': _params.accountId,
1014+
};
1015+
1016+
const sdkHeaders = getSdkHeaders(
1017+
PlatformNotificationsV1.DEFAULT_SERVICE_NAME,
1018+
'v1',
1019+
'replaceNotificationAcknowledgement'
1020+
);
1021+
1022+
const parameters = {
1023+
options: {
1024+
url: '/v1/notifications/acknowledgement',
1025+
method: 'PUT',
1026+
body,
1027+
qs: query,
1028+
},
1029+
defaultOptions: extend(true, {}, this.baseOptions, {
1030+
headers: extend(
1031+
true,
1032+
sdkHeaders,
1033+
this.baseOptions.headers,
1034+
{
1035+
'Accept': 'application/json',
1036+
'Content-Type': 'application/json',
1037+
},
1038+
_params.headers
1039+
),
1040+
axiosOptions: {
1041+
signal: _params.signal,
1042+
},
1043+
}),
1044+
};
1045+
1046+
return this.createRequest(parameters);
1047+
}
9291048
}
9301049

9311050
/*************************
@@ -1139,6 +1258,20 @@ namespace PlatformNotificationsV1 {
11391258
limit?: number;
11401259
}
11411260

1261+
/** Parameters for the `getAcknowledgement` operation. */
1262+
export interface GetAcknowledgementParams extends DefaultParams {
1263+
/** The account ID to retrieve acknowledgement for. */
1264+
accountId?: string;
1265+
}
1266+
1267+
/** Parameters for the `replaceNotificationAcknowledgement` operation. */
1268+
export interface ReplaceNotificationAcknowledgementParams extends DefaultParams {
1269+
/** The ID of a notification. */
1270+
lastAcknowledgedId: string;
1271+
/** The account ID to update acknowledgement for. */
1272+
accountId?: string;
1273+
}
1274+
11421275
/*************************
11431276
* model interfaces
11441277
************************/
@@ -1393,6 +1526,18 @@ namespace PlatformNotificationsV1 {
13931526
message: string;
13941527
}
13951528

1529+
/**
1530+
* Status indicating whether the user has unread notifications.
1531+
*/
1532+
export interface Acknowledgement {
1533+
/** Indicates whether the user has unread notifications. */
1534+
has_unread: boolean;
1535+
/** The ID of the most recent notification available to the user. */
1536+
latest_notification_id: string;
1537+
/** The ID of the last notification acknowledged by the user. */
1538+
last_acknowledged_id: string;
1539+
}
1540+
13961541
/**
13971542
* Prototype for creating an Event Notifications destination entry.
13981543
*/

test/integration/platform-notifications.v1.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,25 @@ describe('PlatformNotificationsV1_integration', () => {
288288
console.log(`Retrieved a total of ${allResults.length} items(s) with pagination.`);
289289
});
290290

291+
test('getAcknowledgement()', async () => {
292+
const res = await platformNotificationsService.getAcknowledgement();
293+
expect(res).toBeDefined();
294+
expect(res.status).toBe(200);
295+
expect(res.result).toBeDefined();
296+
});
297+
298+
test('replaceNotificationAcknowledgement()', async () => {
299+
const params = {
300+
lastAcknowledgedId: '1772804159452',
301+
accountId,
302+
};
303+
304+
const res = await platformNotificationsService.replaceNotificationAcknowledgement(params);
305+
expect(res).toBeDefined();
306+
expect(res.status).toBe(200);
307+
expect(res.result).toBeDefined();
308+
});
309+
291310
test('deleteNotificationPreferences()', async () => {
292311
const params = {
293312
iamId,

0 commit comments

Comments
 (0)