0.3.0 • Published 6 years ago

pigeon-node v0.3.0

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

Pigeon Node

Pigeon Node.js SDK

Usage

const Pigeon = require('pigeon-node');

// Initialize Pigeon SDK
const pigeon = Pigeon.createClient({
  publicKey: process.env.PIGEON_PUBLIC_KEY,
  privateKey: process.env.PIGEON_PRIVATE_KEY,
});

// Start sending messages
pigeon.deliver('message-identifier', { to: 'john@example.com' }).then(_ => console.log('Mail Sent'));

Can also be initialised with no parameters, pigeon-node will look for these env variables PIGEON_PUBLIC_KEY and PIGEON_PRIVATE_KEY.

const Pigeon = require('pigeon-node');

// Initialize Pigeon SDK
const pigeon = Pigeon.createClient();

Examples

Multiple recipients

pigeon.deliver('message-identifier', {
  to: 'John Doe <john@example.com>',
  cc: ['admin@example.com', 'sales@example.com>'],
});

Template variables

pigeon.deliver('message-identifier', {
  to: 'john@example.com',
  data: { name: 'John' },
});

Multiple mails

pigeon.deliver('message-identifier', [
  {
    to: 'John Doe <john@example.com>',
    data: { greet: 'Hi John' },
  },
  {
    to: 'Jane Doe <jane@example.com>',
    data: { greet: 'Hi Jane' },
  },
]);

Attachment support

pigeon.deliver('message-identifier', {
  to: 'jane@example.com',
  attachments: [
    {
      file: '/path/to/handbook.pdf',
      name: 'Handbook',
    },
  ],
});

Use as promise

pigeon.deliver returns a promise so you can chain other tasks after successfully sending mail.

const promise = pigeon.deliver('message-identifier', {
  to: 'John Doe <john@example.com>',
  cc: ['admin@example.com', 'sales@example.com>'],
});

promise
  .then(() => {
    console.log('Mail sent successfully');
    doSomething();
  })
  .catch(e => console.log('Something went wrong', e));

Use with async/await

(async () => {
  try {
    await pigeon.deliver('message-identifier', { to: 'john@example.com' });
  } catch (error) {
    console.log(error);
  }
})();
0.3.0

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago