Microsoft Teams BotBuilder——当团队 ID 以 `thread.skype` 结尾时,频道列表为空

问题描述 投票:0回答:0

我在两个不同的团队中安装了一个机器人。当我为ID以

TeamsInfo.getTeamChannels
结尾的团队做
thread.tacv2
时,我成功获取了频道列表。当我为 ID 以
thread.skype
结尾的团队运行相同的代码时,我收到一个空列表。

完整代码:

package com.mytest;

import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

import com.microsoft.bot.builder.BotFrameworkAdapter;
import com.microsoft.bot.builder.TurnContext;
import com.microsoft.bot.builder.teams.TeamsInfo;
import com.microsoft.bot.connector.authentication.AppCredentials;
import com.microsoft.bot.connector.authentication.SimpleCredentialProvider;
import com.microsoft.bot.schema.ConversationAccount;
import com.microsoft.bot.schema.ConversationReference;
import com.microsoft.bot.schema.teams.ChannelInfo;

public class TestChannelList {

  private String appId;
  private String appPassword;
  private BotFrameworkAdapter bot;
  private ConversationReference installationReference = new ConversationReference();

  public TestChannelList() {
    this.appId = "***";
    this.appPassword = "***";
    this.bot = new BotFrameworkAdapter(new SimpleCredentialProvider(appId, appPassword));

    installationReference.setChannelId("msteams");
    installationReference.setServiceUrl("https://smba.trafficmanager.net/amer/");

//    this works:
//    ConversationAccount conversation = new ConversationAccount(true,
//            "19:***@thread.tacv2",null);
//        conversation.setConversationType("channel");
//        conversation.setTenantId("***");

//    this does not:
    ConversationAccount conversation = new ConversationAccount(true,
        "19:***@thread.skype", "***");
    conversation.setConversationType("channel");
    conversation.setTenantId("***");
    installationReference.setConversation(conversation);

    TurnContext tc = getTurnContextForConversationReference(installationReference);
    CompletableFuture<List<ChannelInfo>> cf = TeamsInfo.getTeamChannels(tc,
        installationReference.getConversation().getId());
    List<ChannelInfo> channels = cf.get();
    System.out.println(channels.size()); // 0 for the `thread.skype` team and non-zero for the `thread.tacv2` team
  }

  public TurnContext getTurnContextForConversationReference(ConversationReference cr)
      {
    // need to do this to avoid 401 errors
   AppCredentials.trustServiceUrl(cr.getServiceUrl());
    TeamsBotCallbackHandler callback = new TeamsBotCallbackHandler();
    CompletableFuture<Void> cf = bot.continueConversation(appId, cr, callback);
    try {
      cf.get();
      return callback.getTurnContext();
    } catch (InterruptedException | ExecutionException e) {
      System.out.println("caught");
      e.printStackTrace();
      return null;
    }
  }

  public static void main(String[] args) {
    new TestChannelList();
  }
}
package com.mytest;

import com.microsoft.bot.builder.BotCallbackHandler;
import com.microsoft.bot.builder.TurnContext;
import java.util.concurrent.CompletableFuture;

public class TeamsBotCallbackHandler implements BotCallbackHandler {

  private TurnContext turnContext;

  @Override
  public CompletableFuture<Void> invoke(TurnContext turnContext) {
    // set the instance field, then the Future should immediately return
    this.turnContext = turnContext;
    return CompletableFuture.completedFuture(null);
  }

  public TurnContext getTurnContext() {
    return turnContext;
  }
}

java botframework
© www.soinside.com 2019 - 2024. All rights reserved.