Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
},
};
102 changes: 102 additions & 0 deletions components/microsoft_teams_bot/actions/send-message/send-message.mjs
Original file line number Diff line number Diff line change
@@ -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;
},
};
24 changes: 24 additions & 0 deletions components/microsoft_teams_bot/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -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,
};
73 changes: 69 additions & 4 deletions components/microsoft_teams_bot/microsoft_teams_bot.app.mjs
Original file line number Diff line number Diff line change
@@ -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,
});
},
},
};
7 changes: 5 additions & 2 deletions components/microsoft_teams_bot/package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "3.0.3"
}
}
}
6 changes: 5 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading