From 3f7935329cbbf71fb89c1e84f76e7d103340205c Mon Sep 17 00:00:00 2001 From: Ben Brown Date: Fri, 21 Aug 2020 16:10:19 -0500 Subject: [PATCH] fix for #1936 - remove dependency on request --- packages/botkit/package.json | 1 - packages/botkit/src/adapter.ts | 26 ++++----------------- packages/testbot/features/teams_features.js | 8 +++++++ 3 files changed, 12 insertions(+), 23 deletions(-) diff --git a/packages/botkit/package.json b/packages/botkit/package.json index 52f7e6744..e9fe2bda7 100644 --- a/packages/botkit/package.json +++ b/packages/botkit/package.json @@ -40,7 +40,6 @@ "express": "^4.17.1", "mustache": "^4.0.1", "path": "^0.12.7", - "request": "^2.88.0", "ware": "^1.3.0" }, "devDependencies": { diff --git a/packages/botkit/src/adapter.ts b/packages/botkit/src/adapter.ts index f09c1bd3a..731959dc9 100644 --- a/packages/botkit/src/adapter.ts +++ b/packages/botkit/src/adapter.ts @@ -5,10 +5,9 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ -import { BotFrameworkAdapter, TurnContext } from 'botbuilder'; +import { BotFrameworkAdapter, TurnContext, TeamsInfo, ChannelInfo } from 'botbuilder'; import { ConnectorClient, TokenApiClient } from 'botframework-connector'; import { TeamsBotWorker } from './teamsHelpers'; -import * as request from 'request'; import * as os from 'os'; const pjson: any = require('../package.json'); // eslint-disable-line @typescript-eslint/no-var-requires @@ -59,27 +58,10 @@ export class BotkitBotFrameworkAdapter extends BotFrameworkAdapter { * @param context A TurnContext object representing a message or event from a user in Teams * @returns an array of channels in the format [{name: string, id: string}] */ - public async getChannels(context: TurnContext): Promise<{id: string; name: string}[]> { + public async getChannels(context: TurnContext): Promise { if (context.activity.channelData && context.activity.channelData.team) { - const token = await this.credentials.getToken(true); - - const uri = context.activity.serviceUrl + 'v3/teams/' + context.activity.channelData.team.id + '/conversations/'; - return new Promise((resolve, reject) => { - request({ - method: 'GET', - headers: { - Authorization: 'Bearer ' + token - }, - json: true, - uri: uri - }, async function(err, res, json) { - if (err) { - reject(err); - } else { - resolve(json.conversations ? json.conversations.map((c) => { if (!c.name) { c.name = 'General'; } return c; }) : []); - } - }); - }); + const channels = await TeamsInfo.getTeamChannels(context); + return channels ? channels.map((c) => { if (!c.name) { c.name = 'General'; } return c; }) : []; } else { console.error('getChannels cannot be called from unknown team'); return []; diff --git a/packages/testbot/features/teams_features.js b/packages/testbot/features/teams_features.js index 2416f79be..6d021b55f 100644 --- a/packages/testbot/features/teams_features.js +++ b/packages/testbot/features/teams_features.js @@ -58,6 +58,14 @@ module.exports = function(controller) { } }); + controller.hears('getTeamChannels', 'message', async(bot, message) => { + try { + await bot.reply(message, JSON.stringify(await bot.teams.getTeamChannels(bot.getConfig('context')))); + } catch(err) { + await bot.reply(message, err.message); + } + }); + controller.hears('getMember', 'message', async(bot, message) => { try {