Skip to content

Commit

Permalink
fix for howdyai#1936 - remove dependency on request
Browse files Browse the repository at this point in the history
  • Loading branch information
benbrown committed Aug 21, 2020
1 parent 9df4e42 commit 3f79353
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 23 deletions.
1 change: 0 additions & 1 deletion packages/botkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
26 changes: 4 additions & 22 deletions packages/botkit/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<ChannelInfo[]> {
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 [];
Expand Down
8 changes: 8 additions & 0 deletions packages/testbot/features/teams_features.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 3f79353

Please sign in to comment.