## Functions

| Function | Description |
|---|---|
| [onMessagePublished(topic, handler)](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.pubsub#pubsubonmessagepublished) | Handle a message being published to a Pub/Sub topic. |
| [onMessagePublished(topic, handler)](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.pubsub#pubsubonmessagepublished) | Handle a message being published to a Pub/Sub topic. |
| [onMessagePublished(options, handler)](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.pubsub#pubsubonmessagepublished) | Handle a message being published to a Pub/Sub topic. |
| [onMessagePublished(options, handler)](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.pubsub#pubsubonmessagepublished) | Handle a message being published to a Pub/Sub topic. |

## Classes

| Class | Description |
|---|---|
| [Message](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.pubsub.message#pubsubmessage_class) | Interface representing a Google Cloud Pub/Sub message. |

## Interfaces

| Interface | Description |
|---|---|
| [MessagePublishedData](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.pubsub.messagepublisheddata#pubsubmessagepublisheddata_interface) | The interface published in a Pub/Sub publish subscription. |
| [PubSubOptions](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.pubsub.pubsuboptions#pubsubpubsuboptions_interface) | PubSubOptions extend EventHandlerOptions but must include a topic. |
| [V1PubSubMessage](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.pubsub.v1pubsubmessage#pubsubv1pubsubmessage_interface) | A v1-compatible Pub/Sub Message. Note: This is a plain object mimicking the v1 Message structure, not an instance of the v1 Message class. |

## pubsub.onMessagePublished()

Handle a message being published to a Pub/Sub topic.

**Signature:**

    export declare function onMessagePublished<T = any>(topic: string | Expression<string>, handler: (event: CloudEvent<MessagePublishedData<T>> & V1Compat<"message", V1PubSubMessage<T>>) => any | Promise<any>): CloudFunction<CloudEvent<MessagePublishedData<T>>>;

### Parameters

| Parameter | Type | Description |
|---|---|---|
| topic | string \| [Expression](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.params.expression#paramsexpression_class)\<string\> | The Pub/Sub topic to watch for message events. |
| handler | (event: [CloudEvent](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.cloudevent#cloudevent_interface)\<[MessagePublishedData](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.pubsub.messagepublisheddata#pubsubmessagepublisheddata_interface)\<T\>\> \& V1Compat\<"message", [V1PubSubMessage](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.pubsub.v1pubsubmessage#pubsubv1pubsubmessage_interface)\<T\>\>) =\> any \| Promise\<any\> | runs every time a Cloud Pub/Sub message is published |

**Returns:**

[CloudFunction](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.cloudfunction#cloudfunction_interface)\<[CloudEvent](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.cloudevent#cloudevent_interface)\<[MessagePublishedData](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.pubsub.messagepublisheddata#pubsubmessagepublisheddata_interface)\<T\>\>\>

## pubsub.onMessagePublished()

Handle a message being published to a Pub/Sub topic.

**Signature:**

    export declare function onMessagePublished<T = any>(topic: string | Expression<string>, handler: (event: CloudEvent<MessagePublishedData<T>>) => any | Promise<any>): CloudFunction<CloudEvent<MessagePublishedData<T>>>;

### Parameters

| Parameter | Type | Description |
|---|---|---|
| topic | string \| [Expression](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.params.expression#paramsexpression_class)\<string\> | The Pub/Sub topic to watch for message events. |
| handler | (event: [CloudEvent](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.cloudevent#cloudevent_interface)\<[MessagePublishedData](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.pubsub.messagepublisheddata#pubsubmessagepublisheddata_interface)\<T\>\>) =\> any \| Promise\<any\> | runs every time a Cloud Pub/Sub message is published |

**Returns:**

[CloudFunction](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.cloudfunction#cloudfunction_interface)\<[CloudEvent](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.cloudevent#cloudevent_interface)\<[MessagePublishedData](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.pubsub.messagepublisheddata#pubsubmessagepublisheddata_interface)\<T\>\>\>

## pubsub.onMessagePublished()

Handle a message being published to a Pub/Sub topic.

**Signature:**

    export declare function onMessagePublished<T = any>(options: PubSubOptions, handler: (event: CloudEvent<MessagePublishedData<T>> & V1Compat<"message", V1PubSubMessage<T>>) => any | Promise<any>): CloudFunction<CloudEvent<MessagePublishedData<T>>>;

### Parameters

| Parameter | Type | Description |
|---|---|---|
| options | [PubSubOptions](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.pubsub.pubsuboptions#pubsubpubsuboptions_interface) | Option containing information (topic) for event |
| handler | (event: [CloudEvent](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.cloudevent#cloudevent_interface)\<[MessagePublishedData](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.pubsub.messagepublisheddata#pubsubmessagepublisheddata_interface)\<T\>\> \& V1Compat\<"message", [V1PubSubMessage](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.pubsub.v1pubsubmessage#pubsubv1pubsubmessage_interface)\<T\>\>) =\> any \| Promise\<any\> | runs every time a Cloud Pub/Sub message is published |

**Returns:**

[CloudFunction](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.cloudfunction#cloudfunction_interface)\<[CloudEvent](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.cloudevent#cloudevent_interface)\<[MessagePublishedData](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.pubsub.messagepublisheddata#pubsubmessagepublisheddata_interface)\<T\>\>\>

## pubsub.onMessagePublished()

Handle a message being published to a Pub/Sub topic.

**Signature:**

    export declare function onMessagePublished<T = any>(options: PubSubOptions, handler: (event: CloudEvent<MessagePublishedData<T>>) => any | Promise<any>): CloudFunction<CloudEvent<MessagePublishedData<T>>>;

### Parameters

| Parameter | Type | Description |
|---|---|---|
| options | [PubSubOptions](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.pubsub.pubsuboptions#pubsubpubsuboptions_interface) | Option containing information (topic) for event |
| handler | (event: [CloudEvent](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.cloudevent#cloudevent_interface)\<[MessagePublishedData](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.pubsub.messagepublisheddata#pubsubmessagepublisheddata_interface)\<T\>\>) =\> any \| Promise\<any\> | runs every time a Cloud Pub/Sub message is published |

**Returns:**

[CloudFunction](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.cloudfunction#cloudfunction_interface)\<[CloudEvent](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.cloudevent#cloudevent_interface)\<[MessagePublishedData](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.pubsub.messagepublisheddata#pubsubmessagepublisheddata_interface)\<T\>\>\>