Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor(options: ConstructorOptions) {
const {
appId,
appSecret,
mapPageToAccessToken,
verifyToken,
batchConfig,
skipProfile,
} = options;
if ('client' in options) {
this._client = options.client;
} else {
const { accessToken, origin, skipAppSecretProof } = options;
this._client = MessengerClient.connect({
accessToken: accessToken || '',
appSecret,
origin,
skipAppSecretProof,
});
}
this._appId = appId;
this._appSecret = appSecret;
this._mapPageToAccessToken = mapPageToAccessToken || null;
this._verifyToken = verifyToken || shortid.generate();
// FIXME: maybe set this default value as true
this._skipProfile = typeof skipProfile === 'boolean' ? skipProfile : false;
export async function deleteGreeting(_: CliContext) {
try {
const config = getConfig('messenger');
invariant(config.accessToken, 'accessToken is not found in config file');
const accessToken = config.accessToken;
const client = MessengerClient.connect(accessToken);
await client.deleteGreeting();
print(`Successfully delete ${bold('greeting')} setting`);
return;
} catch (err) {
error(`Failed to delete ${bold('greeting')} setting`);
if (err.response) {
error(`status: ${bold(err.response.status)}`);
if (err.response.data) {
error(`data: ${bold(JSON.stringify(err.response.data, null, 2))}`);
}
} else {
error(err.message);
}
return process.exit(1);
export async function deleteWhitelistedDomains(_: CliContext) {
try {
const config = getConfig('messenger');
invariant(config.accessToken, 'accessToken is not found in config file');
const accessToken = config.accessToken;
const client = MessengerClient.connect(accessToken);
await client.deleteWhitelistedDomains();
print(`Successfully delete ${bold('whitelisted-domains')} setting`);
return;
} catch (err) {
error(`Failed to delete ${bold('whitelisted-domains')} setting`);
if (err.response) {
error(`status: ${bold(err.response.status)}`);
if (err.response.data) {
error(`data: ${bold(JSON.stringify(err.response.data, null, 2))}`);
}
} else {
error(err.message);
}
return process.exit(1);
try {
const config = getChannelConfig(Channel.Messenger);
const { accessToken } = config;
invariant(
accessToken,
'`accessToken` is not found in the `bottender.config.js` file'
);
invariant(
personaId,
'`id` is required but not found. Use --id to specify persona id'
);
const client = MessengerClient.connect({
accessToken,
});
const persona = await client.getPersona(personaId as string);
if (persona !== undefined) {
print(`Information of persona ${bold(personaId as string)}:`);
print(`Name: ${bold(persona.name)}`);
print(`Profile picture: ${bold(persona.profilePictureUrl)}`);
} else {
print(`Cannot get persona of ID ${bold(personaId as string)}`);
}
} catch (err) {
error(
`Failed to get ${bold('persona')} of ID ${bold(personaId as string)}`
);
invariant(
accessToken,
'`accessToken` is not found in the `bottender.config.js` file'
);
invariant(
personaName,
'`name` is required but not found. Use --name to specify persona name'
);
invariant(
personaUrl,
'`pic` is required but not found. Use --pic to specify persona profile picture url'
);
const client = MessengerClient.connect({
accessToken,
});
const persona = {
name: personaName as string,
profilePictureUrl: personaUrl as string,
};
const personaID = await client.createPersona(persona);
print(`Successfully create ${bold('persona')} ${bold(personaID.id)}`);
} catch (err) {
error(`Failed to create ${bold('persona')}`);
if (err.response) {
error(`status: ${bold(err.response.status)}`);
invariant(
accessToken,
'`accessToken` is not found in the `bottender.config.js` file'
);
invariant(appId, '`appId` is not found in the `bottender.config.js` file');
invariant(
appSecret,
'`appSecret` is not found in the `bottender.config.js` file'
);
invariant(
verifyToken,
'`verifyToken` is not found in the `bottender.config.js` file'
);
const client = MessengerClient.connect({
accessToken,
appId,
appSecret,
});
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();
if (result) {
webhook = `${await getWebhookFromNgrok(ngrokPort)}${path}`;
}
}
try {
const config = getChannelConfig(Channel.Messenger);
const { accessToken } = config;
invariant(
accessToken,
'`accessToken` is not found in the `bottender.config.js` file'
);
invariant(
personaId,
'`id` is required but not found. Use --id to specify persona id'
);
const client = MessengerClient.connect({
accessToken,
});
const res = await client.deletePersona(personaId as string);
if (res.success === true || res.success === 'true') {
print(`Sucessfully delete persona of ID ${bold(personaId as string)}`);
} else {
print(`Cannot get persona of ID ${bold(personaId as string)}`);
}
} catch (err) {
error(
`Failed to delete ${bold('persona')} of ID ${bold(personaId as string)}`
);
if (err.response) {
export async function getGetStarted(_: CliContext) {
try {
const config = getConfig('messenger');
invariant(config.accessToken, 'accessToken is not found in config file');
const accessToken = config.accessToken;
const client = MessengerClient.connect(accessToken);
const getStarted = await client.getGetStarted();
if (getStarted && getStarted.payload) {
print(`Get started payload is: ${bold(getStarted.payload)}`);
} else {
error(`Failed to find ${bold('get_started')} setting`);
}
return;
} catch (err) {
error(`Failed to get ${bold('get_started')} setting`);
if (err.response) {
error(`status: ${bold(err.response.status)}`);
if (err.response.data) {
error(`data: ${bold(JSON.stringify(err.response.data, null, 2))}`);
}