Skip to content

Instantly share code, notes, and snippets.

@manchuck
Created March 2, 2023 16:53
Show Gist options
  • Save manchuck/1fc9c3a4226cb7daca96e51c5037406e to your computer and use it in GitHub Desktop.
Save manchuck/1fc9c3a4226cb7daca96e51c5037406e to your computer and use it in GitHub Desktop.
// You can use this file to test the server-sdk
const { Vonage } = require('@vonage/server-sdk')
const { tokenGenerate } = require('@vonage/jwt');
const { readFileSync } = require('fs');
const VONAGE_API_KEY = process.env.VONAGE_API_KEY
const VONAGE_API_SECRET = process.env.VONAGE_API_SECRET
const appId = '<application id>';
const privateKey = readFileSync(`${__dirname}/private.key`);
const vonage = new Vonage({
apiKey: VONAGE_API_KEY,
apiSecret: VONAGE_API_SECRET,
privateKey: privateKey,
});
// Change what you need below this line
// this is called an IIFE (Immediately Invoked Function Expression)
// It allows async functions to be called until node gets top level async
(async () => {
const to = '<to number>';
const from = '<from number>';
const text = 'Time is an illusion. Lunch time doubly so';
try {
const res = await vonage.sms.send({
from,
to,
text,
clientRef: 'local-client',
});
console.log(res);
} catch (error) {
console.error(error);
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment