Skip to content

DEVEXP-1391: Implement Provisioning API - Webhooks#259

Open
Hurus111 wants to merge 13 commits into
v1.5-nextfrom
DEVEXP-1391-Implement-PAPI-Webhooks
Open

DEVEXP-1391: Implement Provisioning API - Webhooks#259
Hurus111 wants to merge 13 commits into
v1.5-nextfrom
DEVEXP-1391-Implement-PAPI-Webhooks

Conversation

@Hurus111

Copy link
Copy Markdown
Contributor

No description provided.

Comment on lines +13 to +14
const webhookTarget = process.env.WEBHOOK_TARGET ?? 'https://example.com/webhook';
const webhookSecret = process.env.WEBHOOK_SECRET ?? 'MY_WEBHOOK_SECRET';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For these variables, values should come from source itself and to enforce proper values not defaulting to any value if not set:

Suggested change
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';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(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)

Suggested change
const webhookId = process.env.WEBHOOK_ID ?? 'WEBHOOK_ID';
// The ID of the Webhook to retrieve
const webhookId = 'WEBHOOK_ID';

Comment on lines +17 to +19
const response = await sinch.provisioning.webhooks.list({
pageSize: 15,
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 :

Suggested change
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';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const webhookId = process.env.WEBHOOK_ID ?? 'WEBHOOK_ID';
// The ID of the Webhook to delete
const webhookId = 'WEBHOOK_ID';

Comment on lines +13 to +15
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';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

],
};

fixture.list.mockResolvedValue(expectedResponse);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be checked against result wrapped with auto-pagination

Comment on lines +39 to +42
webhooksList = await webhooksApi.list({
pageSize: 15,
});
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +59 to +63
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']);
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specs also define projectId as part of the response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants