Skip to content

Commit

Permalink
Merge 2dce338 into 14b98ce
Browse files Browse the repository at this point in the history
  • Loading branch information
rafael-org committed Apr 8, 2022
2 parents 14b98ce + 2dce338 commit b03bf20
Show file tree
Hide file tree
Showing 11 changed files with 689 additions and 113 deletions.
64 changes: 50 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ This SDK for [Node.js](https://nodejs.org/) was created based on the [Zenvia](ht

## Table of Contents

- [Changelog](#changelog)
- [Features](#features)
- [Prerequisites](#prerequisites)
- [Installation](#installation)
Expand All @@ -31,13 +32,44 @@ This SDK for [Node.js](https://nodejs.org/) was created based on the [Zenvia](ht
- [Contributing](#contributing)
- [License](#license)



## Changelog

### 2.3.0
* Added
* Email content
* Email channel
* Google Business Messages (GBM) channel
* Telegram channel
* Attribute fileName to file content

### 2.2.0
* Added
* Support to custom request headers

### 2.1.1
* Changed
* Fixed template listing

### 2.1.0
* Added
* Instagram channel

### 2.0.0
* Changed
* API endpoint to v2



## Features

- [x] Text message content
- [x] File message content
- [x] Location message content
- [x] Contacts message content
- [x] Template message content
- [x] Email message content
- [x] Send batches
- [x] Subscription handling
- [x] Get reports
Expand Down Expand Up @@ -110,23 +142,27 @@ Examples not listed on this section can be found [here](examples).

The content types that can be sent are:

| Name | Description |
|-----------------|-------------|
| TextContent | Used to send text messages to your customer.
| FileContent | Used to send file messages to your customer.
| LocationContent | Used to send location messages to your customer.
| ContactsContent | Used to send contacts messages to your customer.
| TemplateContent | Used to send template messages to your customer.
| Name | Description |
|-----------------|--------------------------------------------------|
| TextContent | Used to send text messages to your customer. |
| FileContent | Used to send file messages to your customer. |
| LocationContent | Used to send location messages to your customer. |
| ContactsContent | Used to send contacts messages to your customer. |
| TemplateContent | Used to send template messages to your customer. |
| EmailContent | Used to send e-mail messages to your customer. |

The channels that can be used to send the content are:

| Channel | TextContent | FileContent | LocationContent | ContactsContent | TemplateContent |
|----------| :---: | :---: | :---: | :---: | :---: |
| SMS | X | | | | |
| RCS | X | X | | | |
| WhatsApp | X | X | X | X | X |
| Facebook | X | X | | | |
| Instagram| X | X | | | |
| Channel | TextContent | FileContent | LocationContent | ContactsContent | TemplateContent | EmailContent |
|----------| :---: | :---: | :---: | :---: | :---: | :---: |
| SMS | X | | | | | |
| RCS | X | X | | | | |
| WhatsApp | X | X | X | X | X | |
| Facebook | X | X | | | | |
| Instagram| X | X | | | | |
| Email | | | | | | X |
| GBM | X | X | | | | |
| Telegram | X | X | | | | |

Use the `sendMessage` method to messages to your customers.

Expand Down
28 changes: 28 additions & 0 deletions src/lib/channels/email.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { AbstractChannel } from './abstract-channel';
import { ContentType, IContent, ILoggerInstance, IClientOptions } from '../../types';

/**
* Implementation of Email channel.
*/
export class EmailChannel extends AbstractChannel {

private supportedContents: ContentType[];

/**
* Returns a new `EmailChannel` that is used to set the Email channel.
*
* @param token Zenvia platform token.
* @param loggerInstance If you want, you can pass your log instance.
*/
constructor(token: string, loggerInstance: ILoggerInstance, options: IClientOptions) {
super(token, 'email', loggerInstance, options);
this.supportedContents = ['email'];
}

protected contentSupportValidation(content: IContent): void | never {
if (!this.supportedContents.includes(content.type)) {
throw new Error(`Content of type ${content.type} is not supported in E-mail channel`);
}
}

}
28 changes: 28 additions & 0 deletions src/lib/channels/gbm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { AbstractChannel } from './abstract-channel';
import { ContentType, IContent, ILoggerInstance, IClientOptions } from '../../types';

/**
* Implementation of GBM channel.
*/
export class GbmChannel extends AbstractChannel {

private supportedContents: ContentType[];

/**
* Returns a new `GbmChannel` that is used to set the GBM channel.
*
* @param token Zenvia platform token.
* @param loggerInstance If you want, you can pass your log instance.
*/
constructor(token: string, loggerInstance: ILoggerInstance, options: IClientOptions) {
super(token, 'gbm', loggerInstance, options);
this.supportedContents = ['text', 'file'];
}

protected contentSupportValidation(content: IContent): void | never {
if (!this.supportedContents.includes(content.type)) {
throw new Error(`Content of type ${content.type} is not supported in Google Business Messages channel`);
}
}

}
3 changes: 3 additions & 0 deletions src/lib/channels/instagram.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { AbstractChannel } from './abstract-channel';
import { ContentType, IContent, ILoggerInstance, IClientOptions } from '../../types';

/**
* Implementation of Instagram channel.
*/
export class InstagramChannel extends AbstractChannel {

private supportedContents: ContentType[];
Expand Down
2 changes: 1 addition & 1 deletion src/lib/channels/rcs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class RcsChannel extends AbstractChannel {
private supportedContents: ContentType[];

/**
* Returns a new `RCSChannel` that is used to set the RCS channel.
* Returns a new `RcsChannel` that is used to set the RCS channel.
*
* @param token Zenvia platform token.
* @param loggerInstance If you want, you can pass your log instance.
Expand Down
28 changes: 28 additions & 0 deletions src/lib/channels/telegram.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { AbstractChannel } from './abstract-channel';
import { ContentType, IContent, ILoggerInstance, IClientOptions } from '../../types';

/**
* Implementation of Telegram channel.
*/
export class TelegramChannel extends AbstractChannel {

private supportedContents: ContentType[];

/**
* Returns a new `TelegramChannel` that is used to set the Telegram channel.
*
* @param token Zenvia platform token.
* @param loggerInstance If you want, you can pass your log instance.
*/
constructor(token: string, loggerInstance: ILoggerInstance, options: IClientOptions) {
super(token, 'telegram', loggerInstance, options);
this.supportedContents = ['text', 'file'];
}

protected contentSupportValidation(content: IContent): void | never {
if (!this.supportedContents.includes(content.type)) {
throw new Error(`Content of type ${content.type} is not supported in Telegram channel`);
}
}

}
6 changes: 6 additions & 0 deletions src/lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { RcsChannel } from './channels/rcs';
import { InstagramChannel } from './channels/instagram';
import { FacebookChannel } from './channels/facebook';
import { WhatsAppChannel } from './channels/whatsapp';
import { TelegramChannel } from './channels/telegram';
import { GbmChannel } from './channels/gbm';
import { EmailChannel } from './channels/email';
import * as request from '../utils/request';
import { ITemplate, MessageBatch } from '../types/zenvia';
import { ReportFlow } from './reports/report-flow';
Expand Down Expand Up @@ -44,6 +47,9 @@ export class Client {
case 'facebook': return new FacebookChannel(this.token, this.logger, this.options);
case 'whatsapp': return new WhatsAppChannel(this.token, this.logger, this.options);
case 'instagram': return new InstagramChannel(this.token, this.logger, this.options);
case 'telegram': return new TelegramChannel(this.token, this.logger, this.options);
case 'gbm': return new GbmChannel(this.token, this.logger, this.options);
case 'email': return new EmailChannel(this.token, this.logger, this.options);
default: throw new Error('Unsupported channel');
}
}
Expand Down
32 changes: 32 additions & 0 deletions src/lib/contents/email.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { AbstractContent } from './abstract-content';
import { IEmailContent, IFile } from '../../types';

/**
* Implementation of email content.
*/
export class EmailContent extends AbstractContent implements IEmailContent {

subject: string;
html?: string;
text?: string;
attachments?: IFile[];
cc?: string[];
bcc?: string[];

/**
* Returns a new `EmailContent` that can be used to send audio, image, video, or document media to your customer.
*
* @param subject The subject of the e-mail to be sent.
* @param html The content to be sent in HTML format.
* @param text The content to be sent in plain text format.
* @param attachments Files to be attached in the e-mail.
*/
constructor(subject: string, attachments?: IFile[], html?: string, text?: string) {
super('email');
this.subject = subject;
this.html = html;
this.text = text;
this.attachments = attachments;
}

}
5 changes: 4 additions & 1 deletion src/lib/contents/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,22 @@ export class FileContent extends AbstractContent implements IFileContent {
fileUrl: string;
fileMimeType: string;
fileCaption: string;
fileName: string;

/**
* Returns a new `FileContent` that can be used to send audio, image, video, or document media to your customer.
*
* @param url The protocol and URL of the media to be sent. Use only with HTTP/HTTPS URLs.
* @param mimeType A media type to indicates the nature and format of a media.
* @param caption Describes the specified audio, image, video, or document media.
* @param name The file name of the specified audio, image, video, or document media.
*/
constructor(url: string, mimeType: string, caption?: string) {
constructor(url: string, mimeType: string, caption?: string, name?: string) {
super('file');
this.fileUrl = url;
this.fileMimeType = mimeType;
this.fileCaption = caption;
this.fileName = name;
}

}

0 comments on commit b03bf20

Please sign in to comment.