MessagesClient

MessagesClient

Manages Messages. Messages can be SMS, whatsapp messages, etc.

Constructor

new MessagesClient(optionsopt)

Construct an instance of MessagesClient.

Parameters:
Name Type Attributes Description
options object <optional>

The configuration object. See the subsequent parameters for more details.

Properties
Name Type Attributes Description
credentials object <optional>

Credentials object.

Properties
Name Type Attributes Description
client_email string <optional>
private_key string <optional>
email string <optional>

Account email address. Required when using a .pem or .p12 keyFilename.

keyFilename string <optional>

Full path to the a .json, .pem, or .p12 key downloaded from the Google Developers Console. If you provide a path to a JSON file, the projectId option below is not necessary. NOTE: .pem and .p12 require you to specify options.email as well.

port number <optional>

The port on which to connect to the remote host.

projectId string <optional>

The project ID from the Google Developer's Console, e.g. 'grape-spaceship-123'. We will also check the environment variable GCLOUD_PROJECT for your project ID. If your app is running in an environment which supports Application Default Credentials, your project ID will be detected automatically.

apiEndpoint string <optional>

The domain name of the API remote host.

Members

apiEndpoint

The DNS address for this API service - same as servicePath(), exists for compatibility reasons.

port

The port for this API service.

scopes

The scopes needed to make gRPC calls for every method defined in this service.

servicePath

The DNS address for this API service.

Methods

close()

Terminate the GRPC channel and close the client.

The client will no longer be usable and all future behavior is undefined.

createMessage(request, optionsopt) → {Promise}

Creates a Message and queues it for sending. Returns the created message.

The caller must have messaging.messages.create permission on the project.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
parent string

The resource name of the parent project to create the message under. Must be of the form projects/*.

message enfonica.messaging.v1.Message

The message resource to be created.

options object <optional>

Call options. See CallOptions for more details.

Returns:
Type Description
Promise
  • The promise which resolves to an array. The first element of the array is an object representing Message. The promise has a method named "cancel" which cancels the ongoing API call.

getMessage(request, optionsopt) → {Promise}

Retrieves a Message identified by the supplied resource name.

The caller must have messaging.messages.get permission on the project.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
name string

The resource name of the Message to retrieve. Must be of the form projects/* /messages/*.

options object <optional>

Call options. See CallOptions for more details.

Returns:
Type Description
Promise
  • The promise which resolves to an array. The first element of the array is an object representing Message. The promise has a method named "cancel" which cancels the ongoing API call.

getProjectId(callback)

Return the project ID used by this class.

Parameters:
Name Type Description
callback function

the callback to be called with the current project Id.

initialize() → {Promise}

Initialize the client. Performs asynchronous operations (such as authentication) and prepares the client. This function will be called automatically when any class method is called for the first time, but if you need to initialize it before calling an actual method, feel free to call initialize() directly.

You can await on this method if you want to make sure the client is initialized.

Returns:
Type Description
Promise

A promise that resolves to an authenticated service stub.

listMessages(request, optionsopt) → {Promise}

Lists the Messages of the specified project. List returns Messages sorted by create_time descending.

The caller must have messaging.messages.list permission on the project.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
parent string

The resource name of the parent of which to list messages. Must be of the form projects/*.

pageSize number

The maximum number of Messages to return in the response. Default value is 10 and maximum value is 100.

pageToken string

A pagination token returned from a previous call to ListMessages that indicates where this listing should continue from.

startTime google.protobuf.Timestamp

The timestamp (inclusive) from which to retrieve messages. The create_time of the Message is used.

This field is deprecated. Use filter instead. If a value is specified for both start_time and filter, the call will fail.

(-- api-linter: core::0132::request-unknown-fields=disabled aip.dev/not-precedent: List has additional fields in this package. --)

endTime google.protobuf.Timestamp

The timestamp (exclusive) until which to retrieve messages. The create_time of the Message is used.

This field is deprecated. Use filter instead. If a value is specified for both end_time and filter, the call will fail.

(-- api-linter: core::0132::request-unknown-fields=disabled aip.dev/not-precedent: List has additional fields in this package. --)

filter string

Filter string to specify which results should be returned.

The following fields can be filtered:

  • createTime
  • to
  • from
  • status
  • direction
  • encoding

For example: createTime >= '2021-01-01T06:00:00.0Z' AND createTime < '2021-02-01' AND status = DELIVERED OR status = UNDELIVERED AND to = '+61*' OR from = '+61*'

Note that OR has higher precendence than AND.

options object <optional>

Call options. See CallOptions for more details.

Returns:
Type Description
Promise
  • The promise which resolves to an array. The first element of the array is Array of Message. The client library support auto-pagination by default: it will call the API as many times as needed and will merge results from all the pages into this array.

    When autoPaginate: false is specified through options, the array has three elements. The first element is Array of Message that corresponds to the one page received from the API server. If the second element is not null it contains the request object of type ListMessagesRequest that can be used to obtain the next page of the results. If it is null, the next page does not exist. The third element contains the raw response received from the API server. Its type is ListMessagesResponse.

    The promise has a method named "cancel" which cancels the ongoing API call.

listMessagesAsync(request, optionsopt) → {Object}

Equivalent to listMessages, but returns an iterable object.

for-await-of syntax is used with the iterable to recursively get response element on-demand.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
parent string

The resource name of the parent of which to list messages. Must be of the form projects/*.

pageSize number

The maximum number of Messages to return in the response. Default value is 10 and maximum value is 100.

pageToken string

A pagination token returned from a previous call to ListMessages that indicates where this listing should continue from.

startTime google.protobuf.Timestamp

The timestamp (inclusive) from which to retrieve messages. The create_time of the Message is used.

This field is deprecated. Use filter instead. If a value is specified for both start_time and filter, the call will fail.

(-- api-linter: core::0132::request-unknown-fields=disabled aip.dev/not-precedent: List has additional fields in this package. --)

endTime google.protobuf.Timestamp

The timestamp (exclusive) until which to retrieve messages. The create_time of the Message is used.

This field is deprecated. Use filter instead. If a value is specified for both end_time and filter, the call will fail.

(-- api-linter: core::0132::request-unknown-fields=disabled aip.dev/not-precedent: List has additional fields in this package. --)

filter string

Filter string to specify which results should be returned.

The following fields can be filtered:

  • createTime
  • to
  • from
  • status
  • direction
  • encoding

For example: createTime >= '2021-01-01T06:00:00.0Z' AND createTime < '2021-02-01' AND status = DELIVERED OR status = UNDELIVERED AND to = '+61*' OR from = '+61*'

Note that OR has higher precendence than AND.

options object <optional>

Call options. See CallOptions for more details.

Returns:
Type Description
Object

An iterable Object that conforms to @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols.

listMessagesStream(request, optionsopt) → {Stream}

Equivalent to listMessages, but returns a NodeJS Stream object.

This fetches the paged responses for listMessages continuously and invokes the callback registered for 'data' event for each element in the responses.

The returned object has 'end' method when no more elements are required.

autoPaginate option will be ignored.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
parent string

The resource name of the parent of which to list messages. Must be of the form projects/*.

pageSize number

The maximum number of Messages to return in the response. Default value is 10 and maximum value is 100.

pageToken string

A pagination token returned from a previous call to ListMessages that indicates where this listing should continue from.

startTime google.protobuf.Timestamp

The timestamp (inclusive) from which to retrieve messages. The create_time of the Message is used.

This field is deprecated. Use filter instead. If a value is specified for both start_time and filter, the call will fail.

(-- api-linter: core::0132::request-unknown-fields=disabled aip.dev/not-precedent: List has additional fields in this package. --)

endTime google.protobuf.Timestamp

The timestamp (exclusive) until which to retrieve messages. The create_time of the Message is used.

This field is deprecated. Use filter instead. If a value is specified for both end_time and filter, the call will fail.

(-- api-linter: core::0132::request-unknown-fields=disabled aip.dev/not-precedent: List has additional fields in this package. --)

filter string

Filter string to specify which results should be returned.

The following fields can be filtered:

  • createTime
  • to
  • from
  • status
  • direction
  • encoding

For example: createTime >= '2021-01-01T06:00:00.0Z' AND createTime < '2021-02-01' AND status = DELIVERED OR status = UNDELIVERED AND to = '+61*' OR from = '+61*'

Note that OR has higher precendence than AND.

options object <optional>

Call options. See CallOptions for more details.

Returns:
Type Description
Stream

An object stream which emits an object representing Message on 'data' event.

See:

matchMessageFromMessageName(messageName) → {string}

Parse the message from Message resource.

Parameters:
Name Type Description
messageName string

A fully-qualified path representing Message resource.

Returns:
Type Description
string

A string representing the message.

matchProjectFromMessageName(messageName) → {string}

Parse the project from Message resource.

Parameters:
Name Type Description
messageName string

A fully-qualified path representing Message resource.

Returns:
Type Description
string

A string representing the project.

matchProjectFromUnsubscriberName(unsubscriberName) → {string}

Parse the project from Unsubscriber resource.

Parameters:
Name Type Description
unsubscriberName string

A fully-qualified path representing Unsubscriber resource.

Returns:
Type Description
string

A string representing the project.

matchUnsubscriberFromUnsubscriberName(unsubscriberName) → {string}

Parse the unsubscriber from Unsubscriber resource.

Parameters:
Name Type Description
unsubscriberName string

A fully-qualified path representing Unsubscriber resource.

Returns:
Type Description
string

A string representing the unsubscriber.

messagePath(project, message) → {string}

Return a fully-qualified message resource name string.

Parameters:
Name Type Description
project string
message string
Returns:
Type Description
string

Resource name string.

unsubscriberPath(project, unsubscriber) → {string}

Return a fully-qualified unsubscriber resource name string.

Parameters:
Name Type Description
project string
unsubscriber string
Returns:
Type Description
string

Resource name string.