DEVEXP-1391: Implement Provisioning API - Webhooks - #259
Conversation
…h Webhooks API and related configurations
…Webhooks API functionality
| const webhookTarget = process.env.WEBHOOK_TARGET ?? 'https://example.com/webhook'; | ||
| const webhookSecret = process.env.WEBHOOK_SECRET ?? 'MY_WEBHOOK_SECRET'; |
There was a problem hiding this comment.
For these variables, values should come from source itself and to enforce proper values not defaulting to any value if not set:
| const webhookTarget = process.env.WEBHOOK_TARGET ?? 'https://example.com/webhook'; | |
| const webhookSecret = process.env.WEBHOOK_SECRET ?? 'MY_WEBHOOK_SECRET'; | |
| // The URL called by Sinch when sending event | |
| const webhookTarget = 'MY_WEBHOOK_URL'; | |
| // The secret to be used to validate event | |
| const webhookSecret = 'MY_WEBHOOK_SECRET'; |
| const projectId = process.env.SINCH_PROJECT_ID ?? 'MY_PROJECT_ID'; | ||
| const keyId = process.env.SINCH_KEY_ID ?? 'MY_KEY_ID'; | ||
| const keySecret = process.env.SINCH_KEY_SECRET ?? 'MY_KEY_SECRET'; | ||
| const webhookId = process.env.WEBHOOK_ID ?? 'WEBHOOK_ID'; |
There was a problem hiding this comment.
(see other snippets about what could be related to process.env and what is not, e.g.: https://github.com/sinch/sinch-sdk-node/blob/DEVEXP-1391-Implement-PAPI-Webhooks/examples/snippets/conversation/webhooks/get.js)
| const webhookId = process.env.WEBHOOK_ID ?? 'WEBHOOK_ID'; | |
| // The ID of the Webhook to retrieve | |
| const webhookId = 'WEBHOOK_ID'; |
| const response = await sinch.provisioning.webhooks.list({ | ||
| pageSize: 15, | ||
| }); |
There was a problem hiding this comment.
We avoid from snippets to define this parameters: in the past we saw that humans/AI are using out of the box these parameters in production.
Better to have here :
| const response = await sinch.provisioning.webhooks.list({ | |
| pageSize: 15, | |
| }); | |
| const response = await sinch.provisioning.webhooks.list(); |
| const projectId = process.env.SINCH_PROJECT_ID ?? 'MY_PROJECT_ID'; | ||
| const keyId = process.env.SINCH_KEY_ID ?? 'MY_KEY_ID'; | ||
| const keySecret = process.env.SINCH_KEY_SECRET ?? 'MY_KEY_SECRET'; | ||
| const webhookId = process.env.WEBHOOK_ID ?? 'WEBHOOK_ID'; |
There was a problem hiding this comment.
| const webhookId = process.env.WEBHOOK_ID ?? 'WEBHOOK_ID'; | |
| // The ID of the Webhook to delete | |
| const webhookId = 'WEBHOOK_ID'; |
| const webhookId = process.env.WEBHOOK_ID ?? 'WEBHOOK_ID'; | ||
| const webhookTarget = process.env.WEBHOOK_TARGET ?? 'https://example.com/webhook'; | ||
| const webhookSecret = process.env.WEBHOOK_SECRET ?? 'MY_WEBHOOK_SECRET'; |
There was a problem hiding this comment.
| const webhookId = process.env.WEBHOOK_ID ?? 'WEBHOOK_ID'; | |
| const webhookTarget = process.env.WEBHOOK_TARGET ?? 'https://example.com/webhook'; | |
| const webhookSecret = process.env.WEBHOOK_SECRET ?? 'MY_WEBHOOK_SECRET'; | |
| // The ID of the Webhook to retrieve | |
| const webhookId = 'WEBHOOK_ID'; | |
| // The URL called by Sinch when sending event | |
| const webhookTarget = 'MY_WEBHOOK_URL'; | |
| // The secret to be used to validate event | |
| const webhookSecret = 'MY_WEBHOOK_SECRET'; |
| | 'WHATSAPP_TEMPLATE_DELETED' | ||
| | 'WHATSAPP_TEMPLATE_QUALITY_SCORE_UPDATED' | ||
| | 'WHATSAPP_TEMPLATE_REJECTED' | ||
| | 'WHATSAPP_TEMPLATE_STATUS_UPDATED'; |
There was a problem hiding this comment.
Add | string to accept any new values
| * Returns a paginated list of webhooks for the specified project. | ||
| * @param { ListWebhooksRequestData } data - The data to provide to the API call. | ||
| */ | ||
| public async list(data: ListWebhooksRequestData): Promise<ListWebhooksResponse> { |
There was a problem hiding this comment.
Think it should be a ApiListPromise<ListWebhooksResponse> (e.g.: https://github.com/sinch/sinch-sdk-node/blob/DEVEXP-1391-Implement-PAPI-Webhooks/packages/numbers/src/rest/v1/active-number/active-number-api.ts)
| ], | ||
| }; | ||
|
|
||
| fixture.list.mockResolvedValue(expectedResponse); |
There was a problem hiding this comment.
To be checked against result wrapped with auto-pagination
| webhooksList = await webhooksApi.list({ | ||
| pageSize: 15, | ||
| }); | ||
| }); |
There was a problem hiding this comment.
e2e tests should also cover the auto-pagination feature from SDK (e.g.: https://github.com/sinch/sinch-sdk-node/blob/DEVEXP-1391-Implement-PAPI-Webhooks/packages/sms/tests/rest/v1/batches/batches.steps.ts#L179-L206)
| Then('the response contains the provisioning webhook details', () => { | ||
| assert.equal(webhook.id, '01PROVWEBHOOK001'); | ||
| assert.equal(webhook.target, 'https://my-callback-server.com/provisioning-all'); | ||
| assert.deepEqual(webhook.triggers, ['ALL']); | ||
| }); |
There was a problem hiding this comment.
Specs also define projectId as part of the response.
…nt variable dependencies
…djust related tests
JPPortier
left a comment
There was a problem hiding this comment.
We can suppose main README will have to be updated: https://github.com/sinch/sinch-sdk-node/tree/DEVEXP-1391-Implement-PAPI-Webhooks#supported-apis
| // The URL called by Sinch when sending event | ||
| const webhookTarget = 'MY_WEBHOOK_URL'; | ||
| // The secret to be used to validate event | ||
| const webhookSecret = 'MY_WEBHOOK_SECRET'; |
There was a problem hiding this comment.
| const keySecret = process.env.SINCH_KEY_SECRET ?? 'MY_KEY_SECRET'; | ||
|
|
||
| // The URL called by Sinch when sending event | ||
| const webhookTarget = 'MY_WEBHOOK_URL'; |
There was a problem hiding this comment.
See existing snippets to have common pattern about values:
| return; | ||
| } | ||
| console.log(`✅ Found ${response.data.length} Provisioning webhooks.`); | ||
| for (const webhook of response.data) { |
There was a problem hiding this comment.
It is an auto-paginated response right ?
Here the snippets will only log 1st page.
Better to use this form: https://github.com/sinch/sinch-sdk-node/blob/v1.6-next/examples/snippets/conversation/applications/list.js#L24-L26
| // The URL called by Sinch when sending event | ||
| const webhookTarget = 'MY_WEBHOOK_URL'; | ||
| // The secret to be used to validate event | ||
| const webhookSecret = 'MY_WEBHOOK_SECRET'; |
There was a problem hiding this comment.
See comments about variables form
| @@ -0,0 +1,2 @@ | |||
| ## Version 1.5.0 | |||
| @@ -0,0 +1,40 @@ | |||
| { | |||
| "name": "@sinch/provisioning", | |||
| "version": "1.5.0", | |||
| "test:e2e": "cucumber-js" | ||
| }, | ||
| "dependencies": { | ||
| "@sinch/sdk-client": "1.5.0" |
No description provided.