Skip to content

Commit 309171f

Browse files
committed
[ACTION] Microsoft Teams Bot - Reply to Message and Send Message
1 parent 184654d commit 309171f

File tree

6 files changed

+315
-7
lines changed

6 files changed

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

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: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)