diff --git a/components/microsoft_teams_bot/actions/reply-to-message/reply-to-message.mjs b/components/microsoft_teams_bot/actions/reply-to-message/reply-to-message.mjs new file mode 100644 index 0000000000000..ae62d28a96af6 --- /dev/null +++ b/components/microsoft_teams_bot/actions/reply-to-message/reply-to-message.mjs @@ -0,0 +1,110 @@ +import app from "../../microsoft_teams_bot.app.mjs"; +import constants from "../../common/constants.mjs"; + +export default { + key: "microsoft_teams_bot-reply-to-message", + name: "Reply To Message", + description: "Reply to a message in Microsoft Teams. [See the documentation](https://learn.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-connector-quickstart?view=azure-bot-service-4.0#reply-to-the-users-message).", + type: "action", + version: "0.0.1", + props: { + app, + baseUrl: { + propDefinition: [ + app, + "baseUrl", + ], + }, + conversationId: { + propDefinition: [ + app, + "conversationId", + ], + }, + activityId: { + type: "string", + label: "Reply To ID", + description: "ID of the message being replied to. Required for threading messages correctly in Teams conversations. Maps to `event.body.id` from the trigger event.", + }, + fromId: { + propDefinition: [ + app, + "fromId", + ], + }, + fromName: { + propDefinition: [ + app, + "fromName", + ], + }, + toId: { + propDefinition: [ + app, + "toId", + ], + }, + toName: { + propDefinition: [ + app, + "toName", + ], + }, + text: { + propDefinition: [ + app, + "text", + ], + }, + }, + methods: { + replyToMessage({ + conversationId, activityId, ...args + } = {}) { + return this.app.post({ + path: `/conversations/${conversationId}/activities/${activityId}`, + ...args, + }); + }, + }, + async run({ $ }) { + const { + replyToMessage, + baseUrl, + text, + fromId, + fromName, + conversationId, + toId, + toName, + activityId, + } = this; + + const response = await replyToMessage({ + $, + baseUrl, + conversationId, + activityId, + data: { + type: constants.ACTIVITY_TYPE.MESSAGE, + from: { + id: fromId, + name: fromName, + }, + conversation: { + id: conversationId, + }, + recipient: { + id: toId, + name: toName, + }, + text, + replyToId: activityId, + }, + }); + + $.export("$summary", "Successfully replied to message."); + + return response; + }, +}; diff --git a/components/microsoft_teams_bot/actions/send-message/send-message.mjs b/components/microsoft_teams_bot/actions/send-message/send-message.mjs new file mode 100644 index 0000000000000..52bfcca09f51e --- /dev/null +++ b/components/microsoft_teams_bot/actions/send-message/send-message.mjs @@ -0,0 +1,102 @@ +import app from "../../microsoft_teams_bot.app.mjs"; +import constants from "../../common/constants.mjs"; + +export default { + key: "microsoft_teams_bot-send-message", + name: "Send Message", + description: "Send a message in Microsoft Teams. [See the documentation](https://learn.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-connector-api-reference?view=azure-bot-service-4.0#send-to-conversation).", + type: "action", + version: "0.0.1", + props: { + app, + baseUrl: { + propDefinition: [ + app, + "baseUrl", + ], + }, + conversationId: { + propDefinition: [ + app, + "conversationId", + ], + }, + fromId: { + propDefinition: [ + app, + "fromId", + ], + }, + fromName: { + propDefinition: [ + app, + "fromName", + ], + }, + toId: { + propDefinition: [ + app, + "toId", + ], + }, + toName: { + propDefinition: [ + app, + "toName", + ], + }, + text: { + propDefinition: [ + app, + "text", + ], + }, + }, + methods: { + sendMessage({ + conversationId, ...args + } = {}) { + return this.app.post({ + path: `/conversations/${conversationId}/activities`, + ...args, + }); + }, + }, + async run({ $ }) { + const { + sendMessage, + baseUrl, + conversationId, + fromId, + fromName, + toId, + toName, + text, + } = this; + + const response = await sendMessage({ + $, + baseUrl, + conversationId, + data: { + type: constants.ACTIVITY_TYPE.MESSAGE, + from: { + id: fromId, + name: fromName, + }, + conversation: { + id: conversationId, + }, + recipient: { + id: toId, + name: toName, + }, + text, + }, + }); + + $.export("$summary", "Successfully sent message."); + + return response; + }, +}; diff --git a/components/microsoft_teams_bot/common/constants.mjs b/components/microsoft_teams_bot/common/constants.mjs new file mode 100644 index 0000000000000..3540f4db34a78 --- /dev/null +++ b/components/microsoft_teams_bot/common/constants.mjs @@ -0,0 +1,24 @@ +const VERSION_PATH = "v3"; + +const ACTIVITY_TYPE = { + MESSAGE: "message", + CONTACT_RELATION_UPDATE: "contactRelationUpdate", + CONVERSATION_UPDATE: "conversationUpdate", + TYPING: "typing", + END_OF_CONVERSATION: "endOfConversation", + EVENT: "event", + INVOKE: "invoke", + DELETE_USER_DATA: "deleteUserData", + MESSAGE_UPDATE: "messageUpdate", + MESSAGE_DELETE: "messageDelete", + INSTALLATION_UPDATE: "installationUpdate", + MESSAGE_REACTION: "messageReaction", + SUGGESTION: "suggestion", + TRACE: "trace", + HANDOFF: "handoff", +}; + +export default { + VERSION_PATH, + ACTIVITY_TYPE, +}; diff --git a/components/microsoft_teams_bot/microsoft_teams_bot.app.mjs b/components/microsoft_teams_bot/microsoft_teams_bot.app.mjs index 960d05d94d580..6b73f60ea7da9 100644 --- a/components/microsoft_teams_bot/microsoft_teams_bot.app.mjs +++ b/components/microsoft_teams_bot/microsoft_teams_bot.app.mjs @@ -1,11 +1,76 @@ +import { axios } from "@pipedream/platform"; +import constants from "./common/constants.mjs"; + export default { type: "app", app: "microsoft_teams_bot", - propDefinitions: {}, + propDefinitions: { + baseUrl: { + type: "string", + label: "Service URL", + description: "The Teams service endpoint URL from the incoming message. Required for routing responses back to the correct Teams instance, e.g. `event.body.serviceUrl`.", + }, + conversationId: { + type: "string", + label: "Conversation ID", + description: "Unique identifier for the Teams conversation (can be a 1:1 chat, group chat, or channel conversation). Required to send messages to the correct conversation thread. e.g. `event.body.conversation.id`.", + }, + fromId: { + type: "string", + label: "From ID", + description: "The ID of the sender, e.g. `event.body.from.id`.", + }, + fromName: { + type: "string", + label: "From Name", + description: "The name of the sender, e.g. `event.body.from.name`.", + }, + toId: { + type: "string", + label: "Recipient ID", + description: "The ID of the recipient, e.g. `event.body.recipient.id`.", + }, + toName: { + type: "string", + label: "Recipient Name", + description: "The name of the recipient, e.g. `event.body.recipient.name`.", + }, + text: { + type: "string", + label: "Text", + description: "The actual message content to send to Teams. Can include plain text, Markdown, or HTML depending on your formatting needs.", + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + sanitizeBaseUrl(baseUrl) { + return baseUrl.endsWith("/") + ? baseUrl + : `${baseUrl}/`; + }, + getUrl(baseUrl, path) { + return `${this.sanitizeBaseUrl(baseUrl)}${constants.VERSION_PATH}${path}`; + }, + getHeaders(headers) { + return { + ...headers, + "Content-Type": "application/json", + "Authorization": `Bearer ${this.$auth.oauth_access_token}`, + }; + }, + makeRequest({ + $ = this, baseUrl, path, headers, ...args + } = {}) { + return axios($, { + ...args, + url: this.getUrl(baseUrl, path), + headers: this.getHeaders(headers), + }); + }, + post(args = {}) { + return this.makeRequest({ + method: "POST", + ...args, + }); }, }, }; diff --git a/components/microsoft_teams_bot/package.json b/components/microsoft_teams_bot/package.json index 583f15d98e502..ec8d419bcef5a 100644 --- a/components/microsoft_teams_bot/package.json +++ b/components/microsoft_teams_bot/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/microsoft_teams_bot", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Microsoft Teams Bot Components", "main": "microsoft_teams_bot.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "3.0.3" } -} \ No newline at end of file +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5291063421a42..b14f952f4076a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6348,7 +6348,11 @@ importers: specifier: ^3.0.0 version: 3.0.0 - components/microsoft_teams_bot: {} + components/microsoft_teams_bot: + dependencies: + '@pipedream/platform': + specifier: 3.0.3 + version: 3.0.3 components/microsoft_text_translate: {}