AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents
TypeScript ai-agentai-agent-toolsai-agentsai-agents-frameworkmcpmcp-servermcp-toolsmcpsn8n-alternativeno-code-automationworkflowworkflow-automationworkflows
import { createAction, Property } from '@activepieces/pieces-framework';
import { microsoft365CopilotAuth } from '../common/auth';
import { httpClient, HttpMethod } from '@activepieces/pieces-common';
import { getGraphBaseUrl, getMicrosoftCloudFromAuth } from '../common/microsoft-cloud';
export const chatWithCopilot = createAction({
audience: 'both',
auth: microsoft365CopilotAuth,
name: 'chatWithCopilot',
classification: 'READ',
displayName: 'Chat with Copilot',
description:
'Send a message to an existing Copilot conversation or creating a new one and get a response',
aiMetadata: {
description: 'Sends a prompt to Microsoft 365 Copilot and returns its reply, running in one of two modes: continuing an existing thread when a conversation ID is supplied, or silently creating a new conversation first when it is omitted. Use it when you want Copilot itself to reason over Microsoft 365 data and answer; prefer Search Copilot when you only need the matching OneDrive files back. Requires the message text and an IANA time zone, and can optionally ground the answer in web search. Not idempotent: each call posts a new message and, without a conversation ID, creates another conversation.',
idempotent: false,
},
props: {
conversationId: Property.ShortText({
displayName: 'Conversation ID',
description:
'The ID of an existing conversation. If not provided, a new conversation will be created.',
required: false,
}),
messageText: Property.LongText({
displayName: 'Message Text',
required: true,
}),
timeZone: Property.ShortText({
displayName: 'Time Zone',
description:
'User location time zone in IANA format (e.g., America/New_York, Europe/London)',
required: true,
defaultValue: 'UTC',
}),
// additionalContext: Property.Json({
// displayName: 'Additional Context (optional)',
// description:
// 'Array of context objects with "text" and optional "description" properties',
// required: false,
// }),
// contextFiles: Property.Json({
// displayName: 'Context Files (optional)',
// description:
// 'Array of file objects with "uri" property pointing to OneDrive/SharePoint files',
// required: false,
// }),
enableWebSearch: Property.Checkbox({
displayName: 'Enable Web Search Grounding',
required: false,
defaultValue: true,
}),
},
async run(context) {
const {
conversationId,
messageText,
timeZone,
// additionalContext,
// contextFiles,
enableWebSearch,
} = context.propsValue;
const cloud = getMicrosoftCloudFromAuth(context.auth);
const graphBaseUrl = getGraphBaseUrl(cloud);
let activeConversationId = conversationId;
if (!activeConversationId) {
const createResponse = await httpClient.sendRequest({
method: HttpMethod.POST,
url: `${graphBaseUrl}/beta/copilot/conversations`,
headers: {
Authorization: `Bearer ${context.auth.access_token}`,
'Content-Type': 'application/json',
},
body: {}
});
activeConversationId = createResponse.body.id;
}
const locationHint: any = {
timeZone: timeZone,
};
const body: any = {
message: {
text: messageText,
},
locationHint,
};
// if (
// additionalContext &&
// Array.isArray(additionalContext) &&
// additionalContext.length > 0
// ) {
// body.additionalContext = additionalContext;
// }
const contextualResources: any = {};
// if (
// contextFiles &&
// Array.isArray(contextFiles) &&
// contextFiles.length > 0
// ) {
// contextualResources.files = contextFiles as any;
// }
if (enableWebSearch !== undefined) {
contextualResources.webContext = {
isWebEnabled: enableWebSearch,
} as any;
}
if (Object.keys(contextualResources).length > 0) {
body.contextualResources = contextualResources as any;
}
const response: any = await httpClient.sendRequest({
method: HttpMethod.POST,
url: `${graphBaseUrl}/beta/copilot/conversations/${activeConversationId}/chat`,
headers: {
Authorization: `Bearer ${context.auth.access_token}`,
'Content-Type': 'application/json',
},
body: JSON.stringify(body),
});
return response.body.messages[1];
},
});