Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('reject when Viber return not success', () => {
setup();
const ctx = {
argv: {},
};
ViberClient.connect().removeWebhook.mockRejectedValueOnce(
new Error('removeWebhook failed')
);
expect(deleteWebhook(ctx).then).toThrow();
});
constructor(options: ConstructorOptions) {
if ('client' in options) {
this._client = options.client;
} else {
const { accessToken, sender, origin } = options;
this._client = ViberClient.connect(
{
accessToken,
sender,
origin,
},
sender
);
}
this._accessToken = this._client.accessToken;
}
export async function deleteWebhook(_: CliContext): Promise {
try {
const config: ViberConfig = getChannelConfig(Channel.Viber);
const { accessToken, sender } = config;
invariant(
accessToken,
'`accessToken` is not found in the `bottender.config.js` file'
);
invariant(
sender,
'`sender` is not found in the `bottender.config.js` file'
);
const client = ViberClient.connect(
{
accessToken,
sender,
},
sender
);
await client.removeWebhook();
print('Successfully delete Viber webhook');
} catch (err) {
error('Failed to delete Viber webhook');
if (err.response) {
error(`status: ${bold(err.response.status)}`);
if (err.response.data) {
error(`data: ${bold(JSON.stringify(err.response.data, null, 2))}`);
try {
const config: ViberConfig = getChannelConfig(Channel.Viber);
const { accessToken, sender, path = '/webhooks/viber' } = config;
invariant(
accessToken,
'`accessToken` is not found in the `bottender.config.js` file'
);
invariant(
sender,
'`sender` is not found in the `bottender.config.js` file'
);
const client = ViberClient.connect(
{
accessToken,
sender,
},
sender
);
if (!webhook) {
warn('We can not find the webhook callback url you provided.');
const prompt = new Confirm(
`Are you using ngrok (get url from ngrok server on http://127.0.0.1:${ngrokPort})?`
);
const result = await prompt.run();