Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

MS Teams: Property 'api' does not exist on type 'BotWorker' #2201

Open
MoosaSaadat opened this issue Feb 28, 2022 · 10 comments
Open

MS Teams: Property 'api' does not exist on type 'BotWorker' #2201

MoosaSaadat opened this issue Feb 28, 2022 · 10 comments
Assignees

Comments

@MoosaSaadat
Copy link

I need to get the user email. I am trying to run the following feature from the docs:

controller.hears('who am i', 'direct_message, direct_mention', function(bot, message) {
    bot.api.getUserById(message.channel, message.user, function(err, user) {
        if (err) {
          bot.reply(message,'Error loading user:' + err);
        } else {
          bot.reply(message,'You are ' + user.name + ' and your email is ' + user.email + ' and your user id is ' + user.id);
        }
    });
});

But, I get the following error:

error TS2339: Property 'api' does not exist on type 'BotWorker'.

Maybe the docs are outdated? I also tried using the TeamsBotWorker.teams for getMember(). But, I couldn't get it working either.

  • Botkit version: 4.10.0
  • Messaging Platform: MS Teams
  • Node version: v16.13.2
  • OS: Linux
@MoosaSaadat
Copy link
Author

When I use

bot.teams.getTeamDetails(bot.getConfig('context'));

I get the following error:

error TS2576: Property 'getTeamDetails' does not exist on type 'TeamsInfo'. Did you mean to access the static member 'TeamsInfo.getTeamDetails' instead?

@MoosaSaadat
Copy link
Author

@benbrown can you help here?

@benbrown benbrown self-assigned this Mar 2, 2022
@bzoel
Copy link
Contributor

bzoel commented Mar 9, 2022

@MoosaSaadat I'm doing getMember to get user e-mail on 4.10.0

await bot.teams.getMember(bot.getConfig('context'), message.user);

@MoosaSaadat
Copy link
Author

@billyzoellers Although it works fine, I am using TypeScript and get the following error:

Property 'getMember' does not exist on type 'TeamsInfo'. Did you mean to access the static member 'TeamsInfo.getMember' instead? ts(2576)

I have to disable type check in order to compile it

// @ts-nocheck

@MoosaSaadat
Copy link
Author

Btw @benbrown when this issue is resolved, I can create a PR to update docs for using bot.teams.getMember() instead of bot.api.getUserById()

@benbrown
Copy link
Contributor

Hi guys.

For historical accuracy - the doc you linked to in your OP is to the previous version of Botkit, not the current 4.0 version.

Accessing the bot.teams object is what you want to do... However I am not sure how to deal with the static member warning. Disabling the type check should have no impact on the behavior...

@MoosaSaadat
Copy link
Author

@benbrown as per the specification of static:

Neither static methods nor static properties can be called on instances of the class

The error we are facing is also demonstrated in the first example:

class Triple {
  ...
  static calculate(n = 1) {
    return n * 3;
  }
}
...
const tp = new Triple();
...
// This throws because calculate() is a static member, not an instance member.
console.log(tp.calculate());                // 'tp.calculate is not a function'

So, in our case, access to the TeamsInfo class is required. It should be exported from botkit so that we can use it.

@benbrown
Copy link
Contributor

Can you import it directly from the botbuilder library?

https://github.com/howdyai/botkit/blob/main/packages/botkit/src/core.ts#L374

@MoosaSaadat
Copy link
Author

Yes, I can import it directly and it works fine like that. But, I guess it is not a standard practice to import dependencies which are not mentioned in package.json? Also, eslint will show this problem:

'botbuilder' should be listed in the project's dependencies. Run 'npm i -S botbuilder' to add it - eslint [import/no-extraneous-dependencies](https://github.com/import-js/eslint-plugin-import/blob/v2.25.4/docs/rules/no-extraneous-dependencies.md)

Is there a way to list it in dependencies without having to download multiple versions of it? Will have to make sure that the listed dependency has the same version as botkit dependency to avoid unnecessary duplication.

@benbrown
Copy link
Contributor

@MoosaSaadat Correct, you should use the same version of botbuilder as Botkit to avoid conflicts.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants