Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@bandwidth/messaging

Package Overview
Dependencies
Maintainers
8
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bandwidth/messaging

Bandwidth's HTTP Messaging platform

  • 3.0.0
  • npm
  • Socket score

Version published
Weekly downloads
9.9K
increased by2.38%
Maintainers
8
Weekly downloads
 
Created
Source

Getting Started with Messaging

Getting Started

Introduction

Bandwidth's HTTP Messaging platform

Installation

The following section explains how to use the bandwidthLib library in a new project.

Environments

The SDK can be configured to use a different environment for making API calls. Available environments are:

Fields
NameDescription
productionDefault
custom-

Initialize the API Client

The following parameters are configurable for the API Client:

ParameterTypeDescription
baseUrlstringDefault: 'https://www.example.com'
baseUrlstringDefault: 'https://www.example.com'
environmentEnvironmentThe API environment.
Default: Environment.Production
timeoutnumberTimeout for API calls.
Default: 0
basicAuthUserNamestringThe username to use with basic authentication
basicAuthPasswordstringThe password to use with basic authentication

The API client can be initialized as follows:

const client = new Client({
  timeout: 0,
  environment: Environment.Production
  basicAuthUserName: 'BasicAuthUserName',
  basicAuthPassword: 'BasicAuthPassword',
})

Authorization

This API uses Basic Authentication.

Client Class Documentation

MessagingClient

The gateway for the SDK. This class acts as a factory for the Controllers and also holds the configuration of the SDK.

Controllers

NameDescription
aPIProvides access to ApiController

API Reference

List of APIs

  • API

API

List Media

listMedia

async listMedia(
  userId: string,
  continuationToken?: string,
  requestOptions?: RequestOptions
): Promise<ApiResponse<Media[]>>
Parameters
ParameterTypeTagsDescription
userIdstringTemplate, RequiredUser's account ID
continuationTokenstringHeader, OptionalContinuation token used to retrieve subsequent media.
requestOptionsRequestOptionsOptionalPass additional request options.
Response Type

Media[]

Example Usage
const userId = '900000';
const continuationToken = '12345';
try {
  const { result, ...httpResponse } = await apiController.listMedia(userId, continuationToken);
  // Get more response info...
  // const { statusCode, headers } = httpResponse;
} catch(error) {
  if (error instanceof ApiError) {
    const errors = error.result;
    // const { statusCode, headers } = error;
  }
}
Errors
HTTP Status CodeError DescriptionException Class
400400 Request is malformed or invalidMessagingExceptionError
401401 The specified user does not have access to the accountMessagingExceptionError
403403 The user does not have access to this APIMessagingExceptionError
404404 Path not foundMessagingExceptionError
415415 The content-type of the request is incorrectMessagingExceptionError
429429 The rate limit has been reachedMessagingExceptionError
Get Media

getMedia

async getMedia(
  userId: string,
  mediaId: string,
  requestOptions?: RequestOptions
): Promise<ApiResponse<NodeJS.ReadableStream | Blob>>
Parameters
ParameterTypeTagsDescription
userIdstringTemplate, RequiredUser's account ID
mediaIdstringTemplate, RequiredMedia ID to retrieve
Constraints: Pattern: .+
requestOptionsRequestOptionsOptionalPass additional request options.
Response Type

NodeJS.ReadableStream | Blob

Example Usage
const userId = '900000';
const mediaId = '0a610655-ba58';
try {
  const { result, ...httpResponse } = await apiController.getMedia(userId, mediaId);
  // Get more response info...
  // const { statusCode, headers } = httpResponse;
} catch(error) {
  if (error instanceof ApiError) {
    const errors = error.result;
    // const { statusCode, headers } = error;
  }
}
Errors
HTTP Status CodeError DescriptionException Class
400400 Request is malformed or invalidMessagingExceptionError
401401 The specified user does not have access to the accountMessagingExceptionError
403403 The user does not have access to this APIMessagingExceptionError
404404 Path not foundMessagingExceptionError
415415 The content-type of the request is incorrectMessagingExceptionError
429429 The rate limit has been reachedMessagingExceptionError
Upload Media

uploadMedia

async uploadMedia(
  userId: string,
  mediaId: string,
  contentLength: number,
  body: FileWrapper,
  contentType?: string,
  cacheControl?: string,
  requestOptions?: RequestOptions
): Promise<ApiResponse<void>>
Parameters
ParameterTypeTagsDescription
userIdstringTemplate, RequiredUser's account ID
mediaIdstringTemplate, RequiredThe user supplied custom media ID
Constraints: Pattern: .+
contentLengthnumberHeader, RequiredThe size of the entity-body
bodyFileWrapperBody, Required-
contentTypestringHeader, OptionalThe media type of the entity-body
Default: 'application/octet-stream'
cacheControlstringHeader, OptionalGeneral-header field is used to specify directives that MUST be obeyed by all caching mechanisms along the request/response chain.
requestOptionsRequestOptionsOptionalPass additional request options.
Response Type

void

Example Usage
const userId = '900000';
const mediaId = 'my-media-id';
const contentLength = 500;
const body = new FileWrapper(fs.createReadStream('dummy_file'));
const contentType = 'audio/wav';
const cacheControl = 'no-cache';
try {
  const { result, ...httpResponse } = await apiController.uploadMedia(userId, mediaId, contentLength, body, contentType, cacheControl);
  // Get more response info...
  // const { statusCode, headers } = httpResponse;
} catch(error) {
  if (error instanceof ApiError) {
    const errors = error.result;
    // const { statusCode, headers } = error;
  }
}
Errors
HTTP Status CodeError DescriptionException Class
400400 Request is malformed or invalidMessagingExceptionError
401401 The specified user does not have access to the accountMessagingExceptionError
403403 The user does not have access to this APIMessagingExceptionError
404404 Path not foundMessagingExceptionError
415415 The content-type of the request is incorrectMessagingExceptionError
429429 The rate limit has been reachedMessagingExceptionError
Delete Media

deleteMedia

async deleteMedia(
  userId: string,
  mediaId: string,
  requestOptions?: RequestOptions
): Promise<ApiResponse<void>>
Parameters
ParameterTypeTagsDescription
userIdstringTemplate, RequiredUser's account ID
mediaIdstringTemplate, RequiredThe media ID to delete
Constraints: Pattern: .+
requestOptionsRequestOptionsOptionalPass additional request options.
Response Type

void

Example Usage
const userId = '900000';
const mediaId = 'tjdla-4562ld';
try {
  const { result, ...httpResponse } = await apiController.deleteMedia(userId, mediaId);
  // Get more response info...
  // const { statusCode, headers } = httpResponse;
} catch(error) {
  if (error instanceof ApiError) {
    const errors = error.result;
    // const { statusCode, headers } = error;
  }
}
Errors
HTTP Status CodeError DescriptionException Class
400400 Request is malformed or invalidMessagingExceptionError
401401 The specified user does not have access to the accountMessagingExceptionError
403403 The user does not have access to this APIMessagingExceptionError
404404 Path not foundMessagingExceptionError
415415 The content-type of the request is incorrectMessagingExceptionError
429429 The rate limit has been reachedMessagingExceptionError
Get Messages

getMessages

async getMessages(
  userId: string,
  messageId?: string,
  sourceTn?: string,
  destinationTn?: string,
  messageStatus?: string,
  errorCode?: number,
  fromDateTime?: string,
  toDateTime?: string,
  pageToken?: string,
  limit?: number,
  requestOptions?: RequestOptions
): Promise<ApiResponse<BandwidthMessagesList>>
Parameters
ParameterTypeTagsDescription
userIdstringTemplate, RequiredUser's account ID
messageIdstringQuery, OptionalThe ID of the message to search for. Special characters need to be encoded using URL encoding
sourceTnstringQuery, OptionalThe phone number that sent the message
destinationTnstringQuery, OptionalThe phone number that received the message
messageStatusstringQuery, OptionalThe status of the message. One of RECEIVED, QUEUED, SENDING, SENT, FAILED, DELIVERED, DLR_EXPIRED
errorCodenumberQuery, OptionalThe error code of the message
fromDateTimestringQuery, OptionalThe start of the date range to search in ISO 8601 format. Uses the message receive time. The date range to search in is currently 14 days.
toDateTimestringQuery, OptionalThe end of the date range to search in ISO 8601 format. Uses the message receive time. The date range to search in is currently 14 days.
pageTokenstringQuery, OptionalA base64 encoded value used for pagination of results
limitnumberQuery, OptionalThe maximum records requested in search result. Default 100. The sum of limit and after cannot be more than 10000
requestOptionsRequestOptionsOptionalPass additional request options.
Response Type

BandwidthMessagesList

Example Usage
const userId = '900000';
const messageId = '9e0df4ca-b18d-40d7-a59f-82fcdf5ae8e6';
const sourceTn = '%2B15554443333';
const destinationTn = '%2B15554443333';
const messageStatus = 'RECEIVED';
const errorCode = 9902;
const fromDateTime = '2016-09-14T18:20:16.000Z';
const toDateTime = '2016-09-14T18:20:16.000Z';
const pageToken = 'gdEewhcJLQRB5';
const limit = 50;
try {
  const { result, ...httpResponse } = await apiController.getMessages(userId, messageId, sourceTn, destinationTn, messageStatus, errorCode, fromDateTime, toDateTime, pageToken, limit);
  // Get more response info...
  // const { statusCode, headers } = httpResponse;
} catch(error) {
  if (error instanceof ApiError) {
    const errors = error.result;
    // const { statusCode, headers } = error;
  }
}
Errors
HTTP Status CodeError DescriptionException Class
400400 Request is malformed or invalidMessagingExceptionError
401401 The specified user does not have access to the accountMessagingExceptionError
403403 The user does not have access to this APIMessagingExceptionError
404404 Path not foundMessagingExceptionError
415415 The content-type of the request is incorrectMessagingExceptionError
429429 The rate limit has been reachedMessagingExceptionError
Create Message

createMessage

async createMessage(
  userId: string,
  body: MessageRequest,
  requestOptions?: RequestOptions
): Promise<ApiResponse<BandwidthMessage>>
Parameters
ParameterTypeTagsDescription
userIdstringTemplate, RequiredUser's account ID
bodyMessageRequestBody, Required-
requestOptionsRequestOptionsOptionalPass additional request options.
Response Type

BandwidthMessage

Example Usage
const userId = '900000';
const bodyTo: string[] = ['+15554443333', '+15552223333'];
const body: MessageRequest = {
  applicationId: '93de2206-9669-4e07-948d-329f4b722ee2',
  to: bodyTo,
  from: '+15551113333',
};

try {
  const { result, ...httpResponse } = await apiController.createMessage(userId, body);
  // Get more response info...
  // const { statusCode, headers } = httpResponse;
} catch(error) {
  if (error instanceof ApiError) {
    const errors = error.result;
    // const { statusCode, headers } = error;
  }
}
Errors
HTTP Status CodeError DescriptionException Class
400400 Request is malformed or invalidMessagingExceptionError
401401 The specified user does not have access to the accountMessagingExceptionError
403403 The user does not have access to this APIMessagingExceptionError
404404 Path not foundMessagingExceptionError
415415 The content-type of the request is incorrectMessagingExceptionError
429429 The rate limit has been reachedMessagingExceptionError

Model Reference

Structures

Bandwidth Messages List
Class Name

BandwidthMessagesList

Fields
NameTypeTagsDescription
totalCountnumberOptionalTotal number of messages matched by the search
pageInfoPageInfoOptional-
messagesBandwidthMessageItem[]Optional-
Example (as JSON)
{
  "totalCount": null,
  "pageInfo": null,
  "messages": null
}
Bandwidth Message Item
Class Name

BandwidthMessageItem

Fields
NameTypeTagsDescription
messageIdstringOptionalThe message id
accountIdstringOptionalThe account id of the message
sourceTnstringOptionalThe source phone number of the message
destinationTnstringOptionalThe recipient phone number of the message
messageStatusstringOptionalThe status of the message
messageDirectionstringOptionalThe direction of the message relative to Bandwidth. INBOUND or OUTBOUND
messageTypestringOptionalThe type of message. sms or mms
segmentCountnumberOptionalThe number of segments the message was sent as
errorCodenumberOptionalThe numeric error code of the message
receiveTimestringOptionalThe ISO 8601 datetime of the message
carrierNamestringOptionalThe name of the carrier. Not currently supported for MMS, coming soon
Example (as JSON)
{
  "messageId": null,
  "accountId": null,
  "sourceTn": null,
  "destinationTn": null,
  "messageStatus": null,
  "messageDirection": null,
  "messageType": null,
  "segmentCount": null,
  "errorCode": null,
  "receiveTime": null,
  "carrierName": null
}
Page Info
Class Name

PageInfo

Fields
NameTypeTagsDescription
prevPagestringOptionalThe link to the previous page for pagination
nextPagestringOptionalThe link to the next page for pagination
prevPageTokenstringOptionalThe isolated pagination token for the previous page
nextPageTokenstringOptionalThe isolated pagination token for the next page
Example (as JSON)
{
  "prevPage": null,
  "nextPage": null,
  "prevPageToken": null,
  "nextPageToken": null
}
Media
Class Name

Media

Fields
NameTypeTagsDescription
inputStreamunknownOptional-
contentstringOptional-
urlstringOptional-
contentLengthstringOptional-
contentTypestringOptional-
tagsTag[]Optional-
userIdstringOptionalUser's account ID
mediaNamestringOptional-
mediaIdstringOptional-
cacheControlstringOptional-
Example (as JSON)
{
  "inputStream": null,
  "content": null,
  "url": null,
  "contentLength": null,
  "contentType": null,
  "tags": null,
  "userId": null,
  "mediaName": null,
  "mediaId": null,
  "cacheControl": null
}
Tag
Class Name

Tag

Fields
NameTypeTagsDescription
keystringOptional-
valuestringOptional-
Example (as JSON)
{
  "key": null,
  "value": null
}
Deferred Result
Class Name

DeferredResult

Fields
NameTypeTagsDescription
resultunknownOptional-
setOrExpiredbooleanOptional-
Example (as JSON)
{
  "result": null,
  "setOrExpired": null
}
Bandwidth Callback Message
Class Name

BandwidthCallbackMessage

Fields
NameTypeTagsDescription
timestringOptional-
typestringOptional-
tostringOptional-
errorCodestringOptional-
descriptionstringOptional-
messageBandwidthMessageOptional-
Example (as JSON)
{
  "time": null,
  "type": null,
  "to": null,
  "errorCode": null,
  "description": null,
  "message": null
}
Bandwidth Message
Class Name

BandwidthMessage

Fields
NameTypeTagsDescription
idstringOptionalThe id of the message
ownerstringOptionalThe Bandwidth phone number associated with the message
applicationIdstringOptionalThe application ID associated with the message
timestringOptionalThe datetime stamp of the message in ISO 8601
segmentCountnumberOptionalThe number of segments the original message from the user is broken into before sending over to carrier networks
directionstringOptionalThe direction of the message relative to Bandwidth. Can be in or out
tostring[]OptionalThe phone number recipients of the message
Constraints: Unique Items Required
fromstringOptionalThe phone number the message was sent from
mediastring[]OptionalThe list of media URLs sent in the message
Constraints: Unique Items Required
textstringOptionalThe contents of the message
tagstringOptionalThe custom string set by the user
prioritystringOptionalThe priority specified by the user
Example (as JSON)
{
  "id": null,
  "owner": null,
  "applicationId": null,
  "time": null,
  "segmentCount": null,
  "direction": null,
  "to": null,
  "from": null,
  "media": null,
  "text": null,
  "tag": null,
  "priority": null
}
Message Request
Class Name

MessageRequest

Fields
NameTypeTagsDescription
applicationIdstringThe ID of the Application your from number is associated with in the Bandwidth Phone Number Dashboard.
tostring[]The phone number(s) the message should be sent to in E164 format
Constraints: Unique Items Required
fromstringOne of your telephone numbers the message should come from in E164 format
textstringOptionalThe contents of the text message. Must be 2048 characters or less.
mediastring[]OptionalA list of URLs to include as media attachments as part of the message.
tagstringOptionalA custom string that will be included in callback events of the message. Max 1024 characters
priorityPriorityEnumOptionalThe message's priority, currently for toll-free or short code SMS only. Messages with a priority value of "high" are given preference over your other traffic.
Example (as JSON)
{
  "applicationId": "93de2206-9669-4e07-948d-329f4b722ee2",
  "to": [
    "+15554443333",
    "+15552223333"
  ],
  "from": "+15551113333"
}

Enumerations

Priority

The message's priority, currently for toll-free or short code SMS only. Messages with a priority value of "high" are given preference over your other traffic.

Class Name

PriorityEnum

Fields
Name
default
high
Example
default

Exceptions

Messaging Exception
Class Name

MessagingExceptionError

Fields
NameTypeDescription
typestring-
descriptionstring-
Example (as JSON)
{
  "type": "type0",
  "description": "description0"
}

FAQs

Package last updated on 01 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc