1

I have a conversationUpdate event for a channel, that I'm using as the conversationReference in the following code snippet. For some reason, when I try to run this code, I get an error saying "This method is only valid within the scope of a MS Teams Team." even though as far as I can tell, the event I've provided is in the scope of a team (as further proof, conversation.conversationType is channel). Conversely, I am able to call TeamsInfo.getPagedMembers() successfully, which I would expect to fail if I weren't in a team scope.

const proactiveChannelHandler = async (turnContext) => {
  try {
    const teamDetails = await TeamsInfo.getTeamDetails(turnContext);
    if (teamDetails) {
      await turnContext.sendActivity(`The group ID is: ${teamDetails.aadGroupId}`);
    } else {
      await turnContext.sendActivity('This message did not come from a channel in a team.');
    }
  } catch (err) {
      console.error(err);
  }
}

adapter.continueConversation(conversationReference, proactiveChannelHandler);
Dev
  • 2,428
  • 2
  • 14
  • 15
Joseph Blair
  • 1,385
  • 2
  • 12
  • 25

2 Answers2

0

I was able to successfully obtain a list of channels using the below example:

        private static async Task ListChannelsAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
        {
            var channels = await TeamsInfo.GetTeamChannelsAsync(turnContext, null, cancellationToken);

            foreach (var channel in channels)
            {
                if (channel.Name == null)
                    channel.Name = "General";
            }

            await turnContext.SendActivityAsync(MessageFactory.Text($"Channels list: {string.Join(", ", channels.Select(c => c.Name).ToArray())}"), cancellationToken);
        }
Travis L
  • 43
  • 5
0

Looks like the issue was that I was missing the required second argument for the team ID.

Joseph Blair
  • 1,385
  • 2
  • 12
  • 25