readMessages Logic Documentation
Purpose
The readMessages logic node is designed to fetch messages from a specific Microsoft Teams chat. It provides an interface to retrieve and display chat messages, which can be useful for analytics, reporting, or monitoring chat activity. By leveraging the Teams Chat integration, users can automate the retrieval of chat data for further processing or analysis.
Settings
The readMessages node accepts the following settings:
-
chatId
- Input Type: String
- Description: This setting defines the unique identifier of the Teams chat from which messages will be fetched. It is a required parameter, meaning the function cannot be executed without it. If the
chatIdis not provided using theinputsobject, the function will attempt to retrieve it from theconfigobject. - Default Value: None (required)
-
maxResults
- Input Type: Numeric
- Description: This setting determines the maximum number of chat messages to return, with valid values ranging from 1 to 50. If not explicitly provided, it defaults to 25 messages. Adjusting this setting allows users to control the volume of data retrieved, which can impact performance and processing time. If a value less than 1 or greater than 50 is provided, it will be constrained to these bounds.
- Default Value: 25
How It Works
The readMessages function performs the following operations:
-
Initialize Connection: Calls the
BuildConnectionInstancefunction to establish a connection to the Teams chat integration, using the provided context. -
Input Handling: Retrieves the
chatIdandmaxResultsfrom either theinputsor theconfigobject. It ensures that themaxResultsvalue is a valid integer and is within the acceptable range (1-50). -
Error Handling: Checks if
chatIdis provided; if not, it returns an error indicating that the Chat ID is required. This ensures robust error management. -
Fetch Messages: Calls the
listMessagesmethod on the Teams chat integration instance, using the specifiedchatIdandmaxResults. -
Filter Messages: Processes the fetched messages to exclude system messages and format them using the
TeamsChatIntegration.messageToRowfunction. -
Return Data: Compiles the results into an output format that includes the messages and metadata such as the
chatIdand the total number of results. If an error occurs during the process, it catches the error and returns a descriptive error message.
Expected Data
The readMessages node expects the following data:
- Chat ID (
chatId): A valid string representing the unique identifier of the Teams chat. - Maximum Results (
maxResults): An integer defining the number of messages to fetch (default is 25, must be between 1 and 50).
The output generated includes:
- Output Structure:
output1: Contains:data: An array of messages with the following properties for each message:id: Unique identifier of the messagecontent: Text content of the messagesenderName: Name of the message sendercreatedDateTime: Timestamp of when the message was created
metadata: Contains:chatId: The chat ID used to fetch messagestotalResults: Total number of messages fetched
Use Cases & Examples
Use Cases
-
Chat Monitoring for Customer Support: Utilize
readMessagesto retrieve and analyze chat messages in a support channel to evaluate agent performance, response times, and customer sentiment. -
Data Analytics for Team Collaboration: Gather insights from team discussions in a specific project channel to identify frequently discussed topics, which can help in project management and resource allocation.
-
Automated Reporting: Generate automated reports by fetching chat messages at regular intervals and summarizing key points for management review.
Example Configuration
Use Case: Chat Monitoring for Customer Support
In this example, a customer support team wants to monitor the chat messages in their Teams channel identified by the chat ID 12345-abcde. They want to retrieve up to 30 messages for analysis.
Sample Configuration:
{
"inputs": {
"chatId": "12345-abcde",
"maxResults": 30
},
"config": {
"chatId": "default-chat-id", // Fallback if inputs.chatId is not provided
"maxResults": 25 // Default if inputs.maxResults is not provided
}
}In this configuration, readMessages will fetch the last 30 messages from the specified chat, providing valuable insights into the customer interaction patterns within the team.
Note: Make sure to replace default-chat-id in the configuration with a relevant ID if no input is provided. The maxResults value of 30 will ensure that they are getting enough data for monitoring without overwhelming the system.