0
# Message Metadata
1
2
Application-specific data that can be attached to Slack messages to enable rich interactive experiences and custom workflows.
3
4
## Capabilities
5
6
### Message Metadata
7
8
Attach custom application data to messages for enhanced functionality and context.
9
10
```typescript { .api }
11
/**
12
* Application-specific data to attach to Slack message.
13
* @see https://docs.slack.dev/messaging/message-metadata
14
*/
15
interface MessageMetadata {
16
/** Human readable alphanumeric string representing your application's metadata event */
17
event_type: string;
18
/** Free-form object containing whatever data your application wishes to attach */
19
event_payload: {
20
[key: string]: string | number | boolean | MessageMetadataEventPayloadObject | MessageMetadataEventPayloadObject[];
21
};
22
}
23
24
interface MessageMetadataEventPayloadObject {
25
[key: string]: string | number | boolean;
26
}
27
```
28
29
**Usage Examples:**
30
31
```typescript
32
import { MessageMetadata } from "@slack/types";
33
34
// Task management metadata
35
const taskMetadata: MessageMetadata = {
36
event_type: "task_created",
37
event_payload: {
38
task_id: "task_12345",
39
priority: "high",
40
assignee: "U123456789",
41
due_date: "2024-01-15",
42
completed: false,
43
tags: ["urgent", "backend"]
44
}
45
};
46
47
// Survey metadata
48
const surveyMetadata: MessageMetadata = {
49
event_type: "survey_response",
50
event_payload: {
51
survey_id: "survey_67890",
52
response_count: 5,
53
average_rating: 4.2,
54
questions: [
55
{ question_id: "q1", response: "Very satisfied" },
56
{ question_id: "q2", response: "Would recommend" }
57
]
58
}
59
};
60
61
// Using with message posting
62
const message = {
63
channel: "C1234567890",
64
text: "New task has been created",
65
metadata: taskMetadata
66
};
67
```
68
69
### Integration with Events
70
71
Message metadata integrates with the Events API, allowing applications to react to metadata changes:
72
73
```typescript
74
// Message events with metadata
75
interface MessageEvent {
76
type: 'message';
77
channel: string;
78
user: string;
79
text: string;
80
ts: string;
81
metadata?: MessageMetadata;
82
}
83
```
84
85
### Best Practices
86
87
- **Event Type Naming**: Use descriptive, consistent naming for `event_type` values
88
- **Payload Structure**: Keep payloads flat when possible for better performance
89
- **Data Types**: Use appropriate primitive types (string, number, boolean)
90
- **Size Limits**: Be mindful of message size limits when attaching metadata
91
- **Privacy**: Don't include sensitive information in metadata as it may be visible to developers