Get Messages
Retrieves messages from a Microsoft Teams chat or channel.
Common Properties
- Name - The custom name of the node.
- Color - The custom color of the node.
- Delay Before (sec) - Waits in seconds before executing the node.
- Delay After (sec) - Waits in seconds after executing node.
- Continue On Error - Automation will continue regardless of any error. The default value is false.
If ContinueOnError property is true, no error is caught when the project is executed even if Catch node is used.
Input
- Client Id - The client ID from the Connect node. Optional if using direct credentials.
- Team Id - The unique identifier of the team (required if getting channel messages).
- Channel Id - The unique identifier of the channel (required if getting channel messages).
- Chat Id - The unique identifier of the chat (required if getting chat messages).
- Number of Messages - Maximum number of messages to retrieve (default: 10).
Either provide Chat Id OR both Team Id and Channel Id. You cannot use both at the same time.
Output
- Messages - Collection of messages containing:
value- Array of message objects- Each message has:
Id- Message identifierCreatedDateTime- When message was sentBody- Message content object with Content and ContentTypeFrom- Sender informationAttachments- File attachmentsReactions- Message reactions- Additional message metadata
Options
- Credentials - OAuth2 credentials JSON (optional if using Client ID). Allows direct authentication without Connect node.
Examples
Get Channel Messages
Retrieve recent messages from a channel:
team_id = "19:abc123def456..."
channel_id = "19:xyz789abc123..."
number_of_messages = 20
// Get Messages node
// Output: messages collection
msgs = messages.value
console.log("Retrieved " + msgs.length + " messages")
for (msg of msgs) {
sender = msg.From.User.DisplayName
content = msg.Body.Content
time = msg.CreatedDateTime
console.log(sender + " (" + time + "):")
console.log(" " + content)
}
Get Chat Messages
Retrieve messages from a private chat:
chat_id = "19:meeting_abc123..."
number_of_messages = 10
// Get Messages node
// Team Id: (leave empty)
// Channel Id: (leave empty)
// Chat Id: chat_id
// Number of Messages: 10
msgs = message.messages.value
for (msg of msgs) {
console.log(msg.From.User.DisplayName + ": " + msg.Body.Content)
}
Search for Keyword in Messages
Find messages containing specific text:
team_id = "19:abc123def456..."
channel_id = "19:xyz789abc123..."
keyword = "deadline"
// Get Messages node
// Number of Messages: 50
msgs = message.messages.value
// Filter messages
matching = msgs.filter(m =>
m.Body.Content.toLowerCase().includes(keyword.toLowerCase())
)
console.log("Found " + matching.length + " messages with '" + keyword + "'")
for (msg of matching) {
console.log("- " + msg.Body.Content.substring(0, 100))
}
Get Messages with Attachments
Find messages that have file attachments:
chat_id = "19:meeting_abc123..."
number_of_messages = 30
// Get Messages node
msgs = message.messages.value
// Filter for messages with attachments
with_files = msgs.filter(m =>
m.Attachments && m.Attachments.length > 0
)
console.log("Messages with attachments:")
for (msg of with_files) {
console.log("From: " + msg.From.User.DisplayName)
for (att of msg.Attachments) {
console.log(" File: " + att.Name)
}
}
Monitor Recent Messages
Check for new messages since last check:
team_id = "19:abc123def456..."
channel_id = "19:xyz789abc123..."
last_check = "2025-01-20T10:00:00Z"
// Get Messages node
// Number of Messages: 50
msgs = message.messages.value
// Find new messages
new_msgs = msgs.filter(m =>
new Date(m.CreatedDateTime) > new Date(last_check)
)
if (new_msgs.length > 0) {
console.log("New messages: " + new_msgs.length)
for (msg of new_msgs) {
// Process new messages
// Send notifications, update database, etc.
}
}
Extract Message Content
Parse different content types:
chat_id = "19:meeting_abc123..."
// Get Messages node
msgs = message.messages.value
for (msg of msgs) {
content_type = msg.Body.ContentType // "text" or "html"
content = msg.Body.Content
if (content_type === "html") {
// Strip HTML tags for plain text
plain_text = content.replace(/<[^>]*>/g, '')
console.log(plain_text)
} else {
console.log(content)
}
}
Get Message Statistics
Analyze message activity:
team_id = "19:abc123def456..."
channel_id = "19:xyz789abc123..."
number_of_messages = 100
// Get Messages node
msgs = message.messages.value
// Count messages per user
user_counts = {}
for (msg of msgs) {
user = msg.From.User.DisplayName
user_counts[user] = (user_counts[user] || 0) + 1
}
console.log("Message counts by user:")
for (user in user_counts) {
console.log(" " + user + ": " + user_counts[user])
}
Tips for Effective Use
- Pagination: Retrieve more messages by increasing Number of Messages
- Either/Or: Use either Chat Id OR Team+Channel Id, not both
- Content type: Check Body.ContentType (text vs html)
- Sorting: Messages are returned in reverse chronological order (newest first)
- Attachments: Access file information via Attachments array
- Reactions: Check Reactions for message reactions/emojis
- Rate limiting: Don't request too many messages too frequently
- Filtering: Filter messages in your code for specific criteria
Common Errors and Solutions
"Team Id and Chat Id cannot both be empty"
Cause: Neither chat ID nor team/channel IDs provided.
Solution: Provide either chat ID or both team and channel IDs:
// For channel messages
team_id = "19:abc123..."
channel_id = "19:xyz789..."
chat_id = "" // Leave empty
// OR for chat messages
team_id = "" // Leave empty
channel_id = "" // Leave empty
chat_id = "19:meeting_abc123..."
"Channel Id and Chat Id cannot both be empty"
Cause: Team ID provided but no channel ID or chat ID.
Solution: If using team ID, also provide channel ID:
team_id = "19:abc123..."
channel_id = "19:xyz789..." // Required with team_id
"Number of Messages must be greater than zero"
Cause: Invalid or zero message count.
Solution: Use positive number:
number_of_messages = 10 // Or any positive integer
Empty Message List
Cause: No messages in chat/channel or all filtered out.
Solution:
// Get Messages node
msgs = message.messages.value || []
if (msgs.length === 0) {
console.log("No messages found")
} else {
// Process messages
}
Best Practices
- Reasonable limits: Don't request hundreds of messages at once
- Error handling: Handle empty message lists gracefully
- Content parsing: Handle both text and HTML content types
- Null checks: Verify fields exist before accessing
- Timestamp tracking: Track last message time for incremental updates
- Rate limiting: Add delays between repeated message retrievals
- Data storage: Store important messages in database for analysis
- Privacy: Handle message content according to data policies
Message Data Structure
{
"value": [
{
"Id": "1234567890123",
"CreatedDateTime": "2025-01-20T14:30:00Z",
"Body": {
"ContentType": "text",
"Content": "Hello team!"
},
"From": {
"User": {
"Id": "abc-123-def",
"DisplayName": "John Doe",
"UserIdentityType": "aadUser"
}
},
"Attachments": [],
"Reactions": []
}
]
}
Related Nodes
- SendMessage - Send messages to chat or channel
- GetChats - List available chats
- ListChannels - List available channels
- GetChatMembers - Get chat participants