Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function initializeSmsProviders() {
nexmoClient = new Nexmo({
apiKey: fetchEnv('NEXMO_KEY'),
apiSecret: fetchEnv('NEXMO_SECRET'),
})
const availableNumbers = await getAvailableNumbers()
nexmoNumbers = availableNumbers.map((number: any) => ({
phoneNumber: number.msisdn,
code: phoneUtil.getRegionCodeForNumber(phoneUtil.parse('+' + number.msisdn)),
}))
console.log(nexmoNumbers)
}
if ((appId && privateKey) || appConfig) {
const app_config = appConfig.read().app_config;
nexmo = new Nexmo(
{
apiKey: credentials.api_key,
apiSecret: credentials.api_secret,
applicationId: appId || app_config.app_id,
privateKey: privateKey || app_config.private_key
},
{
debug: emitter.debugging,
appendToUserAgent: `nexmo-cli/${packageDetails.version.replace('v', '')}`
}
);
} else {
nexmo = new Nexmo(
{
apiKey: credentials.api_key,
apiSecret: credentials.api_secret
},
{
debug: emitter.debugging,
appendToUserAgent: `nexmo-cli/${packageDetails.version.replace('v', '')}`
}
);
}
} catch(e) {
if (e instanceof TypeError) {
emitter.error(`Could not initialize Nexmo library. Please run 'nexmo setup' to setup the CLI correctly. (${e.message})`);
} else {
if (e.path.indexOf(`.nexmo-app`) !== -1) {
emitter.error(`Could not read application credentials. Please run 'nexmo app:setup' to setup a Nexmo application. (${e.message})`);
export function getNexmoClient() {
if (nexmoClient == null) {
nexmoClient = new Nexmo({
apiKey: functionConfig.shared['nexmo-key'],
apiSecret: functionConfig.shared['nexmo-secret'],
})
}
return nexmoClient
}
import Nexmo from "nexmo";
import { getFormattedPhoneNumber } from "../../../lib/phone-format";
import { Message, PendingMessagePart } from "../../models";
import { getLastMessage } from "./message-sending";
import { log } from "../../../lib";
let nexmo = null;
const MAX_SEND_ATTEMPTS = 5;
if (process.env.NEXMO_API_KEY && process.env.NEXMO_API_SECRET) {
nexmo = new Nexmo({
apiKey: process.env.NEXMO_API_KEY,
apiSecret: process.env.NEXMO_API_SECRET
});
}
async function convertMessagePartsToMessage(messageParts) {
const firstPart = messageParts[0];
const userNumber = firstPart.user_number;
const contactNumber = firstPart.contact_number;
const serviceMessages = messageParts.map(part =>
JSON.parse(part.service_message)
);
const text = serviceMessages
.map(serviceMessage => serviceMessage.text)
.join("");
const initialize = function(config, emitter, appConfig, appId, privateKey) {
var nexmo;
const packageDetails = require(`${__dirname}/../package.json`);
try {
const credentials = config.read().credentials;
if ((appId && privateKey) || appConfig) {
const app_config = appConfig.read().app_config;
nexmo = new Nexmo(
{
apiKey: credentials.api_key,
apiSecret: credentials.api_secret,
applicationId: appId || app_config.app_id,
privateKey: privateKey || app_config.private_key
},
{
debug: emitter.debugging,
appendToUserAgent: `nexmo-cli/${packageDetails.version.replace('v', '')}`
}
);
} else {
nexmo = new Nexmo(
{
apiKey: credentials.api_key,
apiSecret: credentials.api_secret
instanceWith(key, secret) {
return new Nexmo({apiKey: key, apiSecret: secret});
}