Cli-microsoft365: New command: `teams tab get`

Created on 7 Sep 2020  路  8Comments  路  Source: pnp/cli-microsoft365

Usage

teams tab get [options]

Description

Gets information about the specified Microsoft Teams tab

Options

| Option | Description |
| ----------------------- | ----------------------------------------- |
| -i, --teamId [teamId] | The ID of the Microsoft Teams team where the tab is located. Specify either teamId or teamName but not both |
| --teamName [teamName] | The display name of the Microsoft Teams team where the tab is located. Specify either teamId or teamName but not both |
| -c, --channelId [channelId] | The ID of the Microsoft Teams channel where the tab is located. Specify either channelId or channelName but not both |
| --channelName [channelName] | The display name of the Microsoft Teams channel where the tab is located. Specify either channelId or channelName but not both |
| -t, --tabId [tabId] | The ID of the Microsoft Teams tab. Specify either tabId or tabName but not both |
| -t, --tabName [tabName] | The display name of the Microsoft Teams tab. Specify either tabId or tabName but not both |

Additional Information

GET https://graph.microsoft.com/v1.0/teams/7db85d59-5b57-4cb7-9aff-f76da9dbadb5/channels/19:[email protected]/tabs/d1491273-afbf-4034-ad29-6f5afea7121a

When using --teamName option it is possible that multiple Teams can be returned, in this scenario, we should return an error with the list of matching items and their IDs to disambiguate.

Raised from #1722

new feature work in progress

Most helpful comment

Right now we're not using await/async because our test coverage tool doesn't support it yet. This will likely change in the future, but for now you could use promise chaining, like:

let teamId: string;
this
  .getTeamId(...)
  .then(_teamId: string => {
    teamId = _teamId;
    return this.getChannelId(teamId);
  })
  .then(_channelId: string => {
    ...
  })

Makes sense?

All 8 comments

Thanks @garrytrinder
I will work on this.

Hi @garrytrinder, @waldekmastykarz
Do we need to include the options teamName and channelName?
We do not have it for any other teams related get commands.

I think, it will be worth to include. Please ignore my previous comment. :)

I added the name options as they provide a much more user friendly way of using the command.

You are right to point out that other commands don't have these options currently, but this is something that we want to change going forwards,

We will be creating issues to extend other commands to make the CLI more user friendly.

Hi @garrytrinder

I started with a generic method to get the teamId from teamName

public getTeamIdFromTeamName(resource: string, teamName: string): Promise<string> {
    return new Promise((resolve: (result: string) => void, reject: (error: any) => void): void => {
      const teamRequestOptions: any = {
        url: `${resource}/v1.0/me/joinedTeams?$filter=displayName eq '${encodeURIComponent(teamName)}'`,
        headers: {
          accept: 'application/json;odata.metadata=none'
        },
        json: true
      }

      request
        .get<{ value: Team[] }>(teamRequestOptions)
        .then((res: { value: Team[] }): Promise<string> => {
          const teamItem: Team | undefined = res.value[0];

          if (!teamItem) {
            return Promise.reject(`The specified team does not exist in the Microsoft Teams`);
          }

          const teamId: string = res.value[0].id;
          return Promise.resolve(teamId);
        });
    });
  }

public commandAction(cmd: CommandInstance, args: CommandArgs, cb: (err?: any) => void): void {

    let teamId: string = '';

    this
      .getTeamIdFromTeamName(this.resource, args.options.teamName)
      .then((_teamId: string) => {
        teamId = _teamId;
      }, err => {
        cb(new CommandError(err));
      })
.
.
.

But it is getting failrly complicated with nested async calls for channelName and tabName.
Any suggestions?

Why should the calls for channelName and tabName be nested? Couldn't they be standalone methods assuming teamId and just looking up channel/tab name?

Hi @waldekmastykarz
The standalone methods to get id from teamName, channelName or tabName will be asynchronous, like the one I posted earlier getTeamIdFromTeamName.

Is there any mechanism for us like await?
So, we can get the id of team, channel and tab and then make the actual call to get the tab url.
Any pointers are appreciated. Thanks

Right now we're not using await/async because our test coverage tool doesn't support it yet. This will likely change in the future, but for now you could use promise chaining, like:

let teamId: string;
this
  .getTeamId(...)
  .then(_teamId: string => {
    teamId = _teamId;
    return this.getChannelId(teamId);
  })
  .then(_channelId: string => {
    ...
  })

Makes sense?

Was this page helpful?
0 / 5 - 0 ratings