Skip to content

Commit

Permalink
'externalAttributes #145'
Browse files Browse the repository at this point in the history
The `externalAttributes` attribute is an optional field that can be used to add custom information or metadata to the message being sent. This field is useful for attaching additional data that you want to track or associate with the message throughout the sending and receiving process without affecting the main content of the message.

### Details of the `externalAttributes` Attribute

- **Type:** `string`
- **Description:** This field can accept various types of values, including simple strings, booleans, numbers, JSON objects, or JSON arrays. Below are the specifications for the accepted data types:
  - `[string]` - A simple text string.
  - `[string[boolean]]` - A string representing a boolean value.
  - `[string[number]]` - A string representing a numeric value.
  - `[string[Json[Object]]]` - A string containing a JSON object.
  - `[string[Json[Array]]]` - A string containing a JSON array.

### Usage

When you create a message and include the `externalAttributes` field, the specified values are transmitted along with the message. These values are then forwarded to the associated webhook, providing a way to "stamp" the message with additional information that can be used for tracking, auditing, or other analytical or processing purposes.

For example, you could use `externalAttributes` to store a user ID, process status, or any other relevant information you want to associate with the message. When the message is processed by the target system or responded to via webhook, these external attributes are included in the payload of the response, allowing you to use them as needed in your workflow.
  • Loading branch information
jrCleber committed Aug 28, 2024
1 parent 6ed3793 commit 148d308
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
41 changes: 39 additions & 2 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ servers:
- url: http://{dev_host}
variables:
dev_host:
default: 127.0.0.1:8084
default: localhost:8084

paths:
/instance/qrcode/{instanceName}:
Expand Down Expand Up @@ -486,6 +486,7 @@ paths:
example:
number: 123@broadcast
options:
externalAttributes: <any> - optional
delay: 1200
presence: composing
textMessage:
Expand Down Expand Up @@ -605,6 +606,7 @@ paths:
example:
number: <string> - required
options:
externalAttributes: <any> - optional
delay: <integer> - optional
presence: <'composing' | 'recording' | 'paused'> - optional
quotedMessageId: 1
Expand Down Expand Up @@ -656,7 +658,7 @@ paths:
format: binary
mediatype:
type: string
description: '-required - image | document | video | audio'
description: '- **required:** image | document | video | audio'
example: document
presence:
type: string
Expand All @@ -670,6 +672,21 @@ paths:
type: integer
description: '- optional'
example: '1883'
externalAttributes:
type: string
description: |
- optional
---
**Types:**
- `[string]`
- `[string[boolean]]`
- `[string[number]]`
- `[string[Json[Object]]]`
- `[string[Json[Array]]]`
parameters:
- name: instanceName
in: path
Expand Down Expand Up @@ -740,6 +757,7 @@ paths:
example:
number: <string> - required
options:
externalAttributes: <any> - optional
delay: <integer> - optional
presence: <'composing' | 'recording' | 'paused'> - optional
quotedMessageId: 1
Expand Down Expand Up @@ -782,6 +800,7 @@ paths:
example:
number: <string> - required
options:
externalAttributes: <any> - optional
delay: <integer> - optional
presence: <'composing' | 'recording' | 'paused'> - optional
quotedMessageId: 1
Expand Down Expand Up @@ -863,6 +882,7 @@ paths:
example:
number: <string> - required
options:
externalAttributes: <any> - optional
delay: <integer> - optional
quotedMessageId: 1
audioMessage:
Expand Down Expand Up @@ -920,6 +940,21 @@ paths:
type: string
description: Optional ID of the message to be quoted in the conversation.
example: "12345"
externalAttributes:
type: string
description: |
- optional
---
**Types:**
- `[string]`
- `[string[boolean]]`
- `[string[number]]`
- `[string[Json[Object]]]`
- `[string[Json[Array]]]`
responses:
'200':
description: Audio file sent successfully.
Expand Down Expand Up @@ -967,6 +1002,7 @@ paths:
description: "The recipient's phone number."
example: "5531900000000"
options:
externalAttributes: <any> - optional
type: object
properties:
delay:
Expand Down Expand Up @@ -1054,6 +1090,7 @@ paths:
type: string
example: "5531997853327"
options:
externalAttributes: <any> - optional
type: object
properties:
delay:
Expand Down
1 change: 1 addition & 0 deletions src/whatsapp/dto/sendMessage.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export class Options {
presence?: WAPresence;
quotedMessageId?: number;
messageId?: string;
externalAttributes?: any;
}
class OptionsMessage {
options: Options;
Expand Down
2 changes: 2 additions & 0 deletions src/whatsapp/services/whatsapp.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1364,6 +1364,8 @@ export class WAStartupService {
messageSent.id = id;
}

messageSent['externalAttributes'] = options?.externalAttributes;

this.ws.send(this.instance.name, 'send.message', messageSent);
this.sendDataWebhook('sendMessage', messageSent).catch((error) =>
this.logger.error(error),
Expand Down

0 comments on commit 148d308

Please sign in to comment.