n8n-nodes-msteams-botframework 1.2.10 → 1.2.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MsTeamsBotFrameworkTrigger = void 0;
4
- const n8n_workflow_1 = require("n8n-workflow");
5
- const botbuilder_1 = require("botbuilder");
6
4
  // Track processed activity IDs to prevent duplicates
7
5
  const processedActivities = new Map();
8
6
  // Clean up old entries every 5 minutes
@@ -185,145 +183,109 @@ class MsTeamsBotFrameworkTrigger {
185
183
  };
186
184
  }
187
185
  async webhook() {
188
- const node = this.getNode();
189
- let credentials;
190
- try {
191
- credentials = await this.getCredentials('msTeamsBotFrameworkApi');
192
- }
193
- catch (error) {
194
- throw new n8n_workflow_1.NodeOperationError(node, 'Failed to get credentials', {
195
- description: error.message,
196
- });
197
- }
186
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
198
187
  const req = this.getRequestObject();
199
188
  const events = this.getNodeParameter('events', []);
200
189
  const options = this.getNodeParameter('options', {});
201
- const appId = credentials.appId;
202
- const appPassword = credentials.appPassword;
203
- // Create Bot Framework Adapter
204
- const adapter = new botbuilder_1.BotFrameworkAdapter({
205
- appId,
206
- appPassword,
207
- });
208
- // Process the incoming activity
209
- let activityData = null;
210
- let shouldTrigger = false;
211
- try {
212
- await adapter.processActivity(req, req.res, async (context) => {
213
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
214
- const activity = context.activity;
215
- // Check for duplicate activity
216
- const activityKey = `${activity.id}_${activity.timestamp}`;
217
- if (processedActivities.has(activityKey)) {
218
- // Already processed this activity, skip
219
- shouldTrigger = false;
220
- return;
221
- }
222
- // Check if we should process this activity type
223
- if (!events.includes(activity.type)) {
224
- shouldTrigger = false;
225
- return;
226
- }
227
- // Ignore bot messages if configured
228
- if (options.ignoreBotMessages && ((_a = activity.from) === null || _a === void 0 ? void 0 : _a.role) === 'bot') {
229
- shouldTrigger = false;
230
- return;
231
- }
232
- // Mark this activity as processed
233
- processedActivities.set(activityKey, Date.now());
234
- shouldTrigger = true;
235
- // Send typing indicator if auto reply is enabled
236
- if (options.autoReply && activity.type === 'message') {
237
- await context.sendActivity({ type: 'typing' });
238
- }
239
- // Extract useful data from activity
240
- activityData = {
241
- type: activity.type,
190
+ // Get the activity directly from request body
191
+ const activity = req.body;
192
+ // Check for duplicate activity
193
+ const activityKey = `${activity.id}_${activity.timestamp}`;
194
+ if (processedActivities.has(activityKey)) {
195
+ // Already processed this activity, return 200 OK but don't trigger workflow
196
+ return {
197
+ webhookResponse: { status: 'ok' },
198
+ };
199
+ }
200
+ // Check if we should process this activity type
201
+ if (!events.includes(activity.type)) {
202
+ return {
203
+ webhookResponse: { status: 'ok' },
204
+ };
205
+ }
206
+ // Ignore bot messages if configured
207
+ if (options.ignoreBotMessages && ((_a = activity.from) === null || _a === void 0 ? void 0 : _a.role) === 'bot') {
208
+ return {
209
+ webhookResponse: { status: 'ok' },
210
+ };
211
+ }
212
+ // Mark this activity as processed
213
+ processedActivities.set(activityKey, Date.now());
214
+ // Extract useful data from activity
215
+ const activityData = {
216
+ type: activity.type,
217
+ text: activity.text,
218
+ timestamp: activity.timestamp,
219
+ id: activity.id,
220
+ conversation: {
221
+ id: (_b = activity.conversation) === null || _b === void 0 ? void 0 : _b.id,
222
+ name: (_c = activity.conversation) === null || _c === void 0 ? void 0 : _c.name,
223
+ conversationType: (_d = activity.conversation) === null || _d === void 0 ? void 0 : _d.conversationType,
224
+ tenantId: (_e = activity.conversation) === null || _e === void 0 ? void 0 : _e.tenantId,
225
+ },
226
+ from: {
227
+ id: (_f = activity.from) === null || _f === void 0 ? void 0 : _f.id,
228
+ name: (_g = activity.from) === null || _g === void 0 ? void 0 : _g.name,
229
+ aadObjectId: (_h = activity.from) === null || _h === void 0 ? void 0 : _h.aadObjectId,
230
+ role: (_j = activity.from) === null || _j === void 0 ? void 0 : _j.role,
231
+ },
232
+ recipient: {
233
+ id: (_k = activity.recipient) === null || _k === void 0 ? void 0 : _k.id,
234
+ name: (_l = activity.recipient) === null || _l === void 0 ? void 0 : _l.name,
235
+ },
236
+ channelId: activity.channelId,
237
+ serviceUrl: activity.serviceUrl,
238
+ locale: activity.locale,
239
+ };
240
+ // Add type-specific data
241
+ switch (activity.type) {
242
+ case 'message':
243
+ activityData.message = {
242
244
  text: activity.text,
243
- timestamp: activity.timestamp,
244
- id: activity.id,
245
- conversation: {
246
- id: (_b = activity.conversation) === null || _b === void 0 ? void 0 : _b.id,
247
- name: (_c = activity.conversation) === null || _c === void 0 ? void 0 : _c.name,
248
- conversationType: (_d = activity.conversation) === null || _d === void 0 ? void 0 : _d.conversationType,
249
- tenantId: (_e = activity.conversation) === null || _e === void 0 ? void 0 : _e.tenantId,
250
- },
251
- from: {
252
- id: (_f = activity.from) === null || _f === void 0 ? void 0 : _f.id,
253
- name: (_g = activity.from) === null || _g === void 0 ? void 0 : _g.name,
254
- aadObjectId: (_h = activity.from) === null || _h === void 0 ? void 0 : _h.aadObjectId,
255
- role: (_j = activity.from) === null || _j === void 0 ? void 0 : _j.role,
256
- },
257
- recipient: {
258
- id: (_k = activity.recipient) === null || _k === void 0 ? void 0 : _k.id,
259
- name: (_l = activity.recipient) === null || _l === void 0 ? void 0 : _l.name,
260
- },
261
- channelId: activity.channelId,
262
- serviceUrl: activity.serviceUrl,
263
- locale: activity.locale,
245
+ textFormat: activity.textFormat,
246
+ attachments: activity.attachments,
247
+ mentions: (_m = activity.entities) === null || _m === void 0 ? void 0 : _m.filter((e) => e.type === 'mention'),
264
248
  };
265
- // Add type-specific data
266
- switch (activity.type) {
267
- case 'message':
268
- activityData.message = {
269
- text: activity.text,
270
- textFormat: activity.textFormat,
271
- attachments: activity.attachments,
272
- mentions: (_m = activity.entities) === null || _m === void 0 ? void 0 : _m.filter((e) => e.type === 'mention'),
273
- };
274
- break;
275
- case 'conversationUpdate':
276
- activityData.conversationUpdate = {
277
- membersAdded: activity.membersAdded,
278
- membersRemoved: activity.membersRemoved,
279
- };
280
- break;
281
- case 'messageReaction':
282
- activityData.messageReaction = {
283
- reactionsAdded: activity.reactionsAdded,
284
- reactionsRemoved: activity.reactionsRemoved,
285
- replyToId: activity.replyToId,
286
- };
287
- break;
288
- case 'messageUpdate':
289
- activityData.messageUpdate = {
290
- text: activity.text,
291
- updatedText: activity.text,
292
- };
293
- break;
294
- case 'messageDelete':
295
- activityData.messageDelete = {
296
- deletedMessageId: activity.id,
297
- };
298
- break;
299
- }
300
- // Include raw activity if requested
301
- if (options.includeRawActivity) {
302
- activityData.rawActivity = activity;
303
- }
304
- });
305
- if (!shouldTrigger || !activityData) {
306
- // Don't trigger workflow - Bot Framework Adapter already sent 200 OK
307
- return {
308
- noWebhookResponse: true,
249
+ break;
250
+ case 'conversationUpdate':
251
+ activityData.conversationUpdate = {
252
+ membersAdded: activity.membersAdded,
253
+ membersRemoved: activity.membersRemoved,
309
254
  };
310
- }
311
- // Return the activity data to the workflow
312
- return {
313
- workflowData: [
314
- [
315
- {
316
- json: activityData,
317
- },
318
- ],
319
- ],
320
- };
255
+ break;
256
+ case 'messageReaction':
257
+ activityData.messageReaction = {
258
+ reactionsAdded: activity.reactionsAdded,
259
+ reactionsRemoved: activity.reactionsRemoved,
260
+ replyToId: activity.replyToId,
261
+ };
262
+ break;
263
+ case 'messageUpdate':
264
+ activityData.messageUpdate = {
265
+ text: activity.text,
266
+ updatedText: activity.text,
267
+ };
268
+ break;
269
+ case 'messageDelete':
270
+ activityData.messageDelete = {
271
+ deletedMessageId: activity.id,
272
+ };
273
+ break;
321
274
  }
322
- catch (error) {
323
- throw new n8n_workflow_1.NodeOperationError(node, `Failed to process Teams webhook: ${error.message}`, {
324
- description: error.message,
325
- });
275
+ // Include raw activity if requested
276
+ if (options.includeRawActivity) {
277
+ activityData.rawActivity = activity;
326
278
  }
279
+ // Return the activity data to the workflow
280
+ return {
281
+ workflowData: [
282
+ [
283
+ {
284
+ json: activityData,
285
+ },
286
+ ],
287
+ ],
288
+ };
327
289
  }
328
290
  }
329
291
  exports.MsTeamsBotFrameworkTrigger = MsTeamsBotFrameworkTrigger;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-msteams-botframework",
3
- "version": "1.2.10",
3
+ "version": "1.2.11",
4
4
  "description": "n8n node for MS Teams Azure Bot Framework",
5
5
  "keywords": [
6
6
  "n8n-community-node-package",