Back

Tutorials

Jun 12, 2023

How to send invoice e-mail with attachments in Node.js using Engagespot API

Amal Raju

Introduction

Infin is a software that allows users to create and send invoices to their clients. To enhance its functionality, Infin has decided to integrate Engagespot's notification API, which will allow users to send notifications to their clients via web and mobile push notifications, with an attached PDF invoice. In this blog post, we will go over the benefits of using Engagespot's notification API and sending notifications with attachments in the context of Infin's invoice creation and sending software.

Engagespot Notification API

Engagespot is a notification API that provides web and mobile push notifications to users. Infin has decided to integrate Engagespot's notification API with its software to allow users to send notifications to their clients when an invoice is created or updated.

Here are some of the key benefits of using Engagespot's notification API

1.Multi-channel communication: Engagespot's notification API allows users to send notifications to their clients via web and mobile push notifications, email, SMS, and more.

2. Real-Time Analytics: Engagespot provides real-time analytics that allow users to track engagement and optimize their messaging for better results.

3. Customizable Templates: Engagespot provides customizable templates for notifications, which can be branded to match a user's business.

4. Easy Integration: Engagespot can be easily integrated with a user's existing software or website, making it easy to start using right away.

Why Infin might want to send notifications with attachments ?

  1. Streamlined Communication: Sending notifications with attachments can help streamline communication between Infin and its clients. By including a PDF invoice with the notification, clients can quickly and easily view important invoice information without needing to log into the Infin software

  2. Improved Client Experience: Providing clients with a clear and concise invoice that is easy to read and understand can improve the overall client experience. This can lead to increased customer satisfaction and loyalty.

  3. Reduced Administrative Tasks: By automating the process of sending notifications with attachments, Infin can reduce administrative tasks and free up time for other important business tasks.

Benefits of Sending Notifications with Attachments

  1. Increased Efficiency: Sending notifications with attachments can help increase efficiency by automating the process of communicating important information to clients. This can help reduce the time and effort required to manually send invoices to clients.

  2. Improved Client Engagement: Providing clients with a clear and concise invoice that is easy to read and understand can improve client engagement. This can lead to increased customer satisfaction and loyalty.

  3. Enhanced Professionalism: Sending notifications with attachments can enhance the professionalism of Infin's communication with clients. By providing a clear and professional invoice with the notification, Infin can demonstrate its commitment to providing quality service. Now, let's take a closer look at how Infin integrated Engagespot into its software to streamline its invoicing process and improve communication with its clients.

Setup Engagespot

It's not a difficult task to send an email notification with an attachment via Engagespot. All you need are an API key, API secret, and a template ID, which you can find in the Engagespot dashboard. Additionally, Engagespot allows you to design your email template within the platform.

Basic setups to send a notification via Engagespot

We can use NodeJS SDK to send a notification, which makes it very easy to do the process. Install the SDK

 npm i @engagespot/node

We have only 3 steps to send an invoice attachment

  • Authenticate

  • Create a user in engage spot

  • Send notification

  1. Copy the API key and secret from Engagespot dashboard to the environment

ENGAGESPOT_API_KEY=############# 
ENGAGESPOT_API_SECRET

  1. Authenticate the client using SDK

    import { EngagespotClient } from '@engagespot/node';
    import { ConfigService } from '@nestjs/config';
    export class EngagespotService {
     Const client = EngagespotClient({
               apiKey: this.configService.get('ENGAGESPOT_API_KEY'),
               apiSecret: this.configService.get(
               'ENGAGESPOT_API_SECRET')
           });
  2. Create a user on engagespot

    const identifier = "john@gmail.com"; // unique identifier
    await client.createOrUpdateUser(identifier, {
                   phoneNumber: "000000000",
                   name: "john",
                   //profile data whatever you want
               });

Creating a user account is a one-time process. Once you create a user, you do not need to create a new account each time you send a notification

  1. Send notification

 await client.send({
               notification: {
                   templateId: template_id,//from engagespot
               },
               data: data,
               recipients:[“john @gmail.com”],
           });

These are the basic concepts of sending notifications through engagespot.

Send Invoice Notification

The first step in the integration process is to create a service called engagespotService, which enables the sending of notifications from anywhere in our code. Next, we created a sendNotification() function that is responsible for sending notifications through Engagespot. To send a notification from our code, we can use the engagespotService.sendNotification() function. This is how our EngagespotService and sendNotification function looks like.

import { ConfigService } from '@nestjs/config';
import { EngagespotClient } from '@engagespot/node';
export class EngagespotService {
   constructor(private readonly configService: ConfigService) {}
   async sendNotification(templateId: Number, recipients: any, data?: object) {
       const client = EngagespotClient({
           apiKey: this.configService.get('ENGAGESPOT_API_KEY');
           apiSecret: this.configService.get(
               'ENGAGESPOT_API_SECRET',
           );
       });
       await client.send({
           notification: {
               templateId: templateId,
           },
           data: data,
           recipients: recipients,
       });
   }
}

We can send the invoice notification with an attachment by calling the sendNotification() method Example :

const invoiceHash = "" // base64 hash of the file
const templateId = 1234 // invoice notification’s template id from engagespot dashboard
const identifier = "john@gmail.com" //unique identifier in engagespot
const data = {
   // invoice details as key-value pairs
   invoice_number: "INV-0001",//example
   attachments: [
       {
           content: invoiceHash,//
           name: "INV-0001.pdf", // name for the attachment
           contentType: 'application/pdf',
       },
   ]
}
this.engagespotService.sendNotification(templateId, [identifier], data);

With the attachment key we can send multiple attachments

attachments: [
       {
           content: invoiceHash,//
           name: "INV-0001.pdf", // name for the attachment
           contentType: 'application/pdf',
       },

Conclusion

Infin's integration of Engagespot has been instrumental in streamlining its invoicing process and improving communication with its clients. By automating the process of sending notifications and including PDF attachments, Infin has been able to save time and improve the user experience for its clients. Engagespot's key features such as multi-channel communication, customizable templates have also helped Infin to personalize its messaging and drive better results. With Engagespot, Infin has taken an important step towards achieving its goal of providing a seamless and efficient invoicing experience for its clients. If you're looking to improve your communication with clients and streamline your business processes, Engagespot could be a valuable tool to consider.

Amal Raju

Share this post