Skip to content

Commit d2b1fea

Browse files
committed
[ACTION] Microsoft Teams Bot - Reply to Message
1 parent cba1e19 commit d2b1fea

File tree

5 files changed

+150
-8
lines changed

5 files changed

+150
-8
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import app from "../../microsoft_teams_bot.app.mjs";
2+
3+
export default {
4+
key: "microsoft_teams_bot-reply-to-message",
5+
name: "Reply To Message",
6+
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).",
7+
type: "action",
8+
version: "0.0.1",
9+
props: {
10+
app,
11+
baseUrl: {
12+
type: "string",
13+
label: "Service URL",
14+
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`.",
15+
},
16+
conversationId: {
17+
type: "string",
18+
label: "Conversation ID",
19+
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`.",
20+
},
21+
fromId: {
22+
type: "string",
23+
label: "From ID",
24+
description: "The ID of the sender, e.g. `event.body.from.id`.",
25+
},
26+
fromName: {
27+
type: "string",
28+
label: "From Name",
29+
description: "The name of the sender, e.g. `event.body.from.name`.",
30+
},
31+
toId: {
32+
type: "string",
33+
label: "Recipient ID",
34+
description: "The ID of the recipient, e.g. `event.body.recipient.id`.",
35+
},
36+
toName: {
37+
type: "string",
38+
label: "Recipient Name",
39+
description: "The name of the recipient, e.g. `event.body.recipient.name`.",
40+
},
41+
activityId: {
42+
type: "string",
43+
label: "Reply To ID",
44+
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.",
45+
},
46+
text: {
47+
type: "string",
48+
label: "Text",
49+
description: "The actual message content to send to Teams. Can include plain text, Markdown, or HTML depending on your formatting needs.",
50+
},
51+
},
52+
methods: {
53+
replyToMessage({
54+
conversationId, activityId, ...args
55+
} = {}) {
56+
return this.app.post({
57+
path: `/conversations/${conversationId}/activities/${activityId}`,
58+
...args,
59+
});
60+
},
61+
},
62+
async run({ $ }) {
63+
const {
64+
replyToMessage,
65+
baseUrl,
66+
text,
67+
fromId,
68+
fromName,
69+
conversationId,
70+
toId,
71+
toName,
72+
activityId,
73+
} = this;
74+
75+
const response = await replyToMessage({
76+
$,
77+
baseUrl,
78+
conversationId,
79+
activityId,
80+
data: {
81+
type: "message",
82+
from: {
83+
id: fromId,
84+
name: fromName,
85+
},
86+
conversation: {
87+
id: conversationId,
88+
},
89+
recipient: {
90+
id: toId,
91+
name: toName,
92+
},
93+
text,
94+
replyToId: activityId,
95+
},
96+
});
97+
98+
$.export("$summary", "Successfully replied to message.");
99+
100+
return response;
101+
},
102+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const VERSION_PATH = "v3";
2+
3+
export default {
4+
VERSION_PATH,
5+
};
Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,40 @@
1+
import { axios } from "@pipedream/platform";
2+
import constants from "./common/constants.mjs";
3+
14
export default {
25
type: "app",
36
app: "microsoft_teams_bot",
47
propDefinitions: {},
58
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
9+
sanitizeBaseUrl(baseUrl) {
10+
return baseUrl.endsWith("/")
11+
? baseUrl
12+
: `${baseUrl}/`;
13+
},
14+
getUrl(baseUrl, path) {
15+
return `${this.sanitizeBaseUrl(baseUrl)}${constants.VERSION_PATH}${path}`;
16+
},
17+
getHeaders(headers) {
18+
return {
19+
...headers,
20+
"Content-Type": "application/json",
21+
"Authorization": `Bearer ${this.$auth.oauth_access_token}`,
22+
};
23+
},
24+
makeRequest({
25+
$ = this, baseUrl, path, headers, ...args
26+
} = {}) {
27+
return axios($, {
28+
...args,
29+
url: this.getUrl(baseUrl, path),
30+
headers: this.getHeaders(headers),
31+
});
32+
},
33+
post(args = {}) {
34+
return this.makeRequest({
35+
method: "POST",
36+
...args,
37+
});
938
},
1039
},
1140
};

components/microsoft_teams_bot/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/microsoft_teams_bot",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Microsoft Teams Bot Components",
55
"main": "microsoft_teams_bot.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "3.0.3"
1417
}
15-
}
18+
}

pnpm-lock.yaml

Lines changed: 6 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)