Предварительно отправлять сообщения в командный чат в Microsoft Teams с помощью Microsoft Bot Framework V4 - PullRequest
0 голосов
/ 20 ноября 2018

Я пытаюсь предварительно отправить специальное сообщение от моего бота, размещенного на Azure, в командный чат Microsoft Teams. Я успешно отправил сообщение в чат 1 на 1, который есть у пользователя с ботом.

Я видел эту документацию , подробно описывающую, как это сделать, однако я считаю, что это Bot Framework версии 3. Он использует пакет слепков Microsoft.Bot.Connector.Teams.Models, который больше не поддерживается. в версии 4. Я не смог найти документацию для этого.

Чтобы быть немного более информативным:

У меня есть бот, который получает POST-запросы от моего веб-приложения с данными тревоги. Когда бот получает один из этих запросов POST, он пересылает сообщение в командный чат. Это сообщение будет отправлено вне контекста. Мой код для пересылки в чат 1 на 1 можно найти здесь.

/// <summary>
    /// Forwards a message to a personal chat.
    /// The details of who to send the message to is included in the <paramref name="forwardContext"/>.
    /// </summary>
    /// <param name="forwardContext">JSON of the recipient details.</param>
    /// <param name="messageToSend">Text message to send to chat.</param>
    /// <returns>A <see cref="Task"/> representing the asynchronous messsage forward.</returns>
    private async Task ForwardMessageToPersonalChatAsync(JToken forwardContext, string messageToSend)
    {
        // Collect data from JSON input
        var restCmd = forwardContext;
        var toId = (string)restCmd["toId"];
        var toName = (string)restCmd["toName"];
        var fromId = (string)restCmd["fromId"];
        var fromName = (string)restCmd["fromName"];
        var channelId = (string)restCmd["channel"];
        var serviceURL = (string)restCmd["serviceURL"];
        var conversationId = (string)restCmd["conversation"];
        var tenant = (string)restCmd["tenant"];
        var cred_str = $@"toId: {toId}
        toName: {toName}
        fromId: {fromId}
        fromName: {fromName}
        channelId: {channelId}
        serviceURL: {serviceURL}
        conversationId: {conversationId}";
        this.logger.LogInformation(cred_str);
        this.logger.LogInformation($"Forwarding the following message to {toName}: {messageToSend}");

        var uri = new System.Uri(serviceURL);

        Dictionary<string, string> botCreds = this.GetBotCredentials();
        ConnectorClient connector = new ConnectorClient(uri, botCreds["App ID"], botCreds["App Password"]);
        var activity = new Activity
        {
            Type = ActivityTypes.Message,
            From = new ChannelAccount(fromId, fromName),
            Recipient = new ChannelAccount(toId, toName),
            Conversation = new ConversationAccount(false, "personal", conversationId),
            Text = messageToSend,
        };

        try
        {
            MicrosoftAppCredentials.TrustServiceUrl(serviceURL);
            await connector.Conversations.SendToConversationAsync(conversationId, activity);
        }
        catch (System.Exception ex)
        {
            this.logger.LogError(ex.ToString());
        }
    }

Как отправить проактивное сообщение в командный чат?

Спасибо за любую помощь.

1 Ответ

0 голосов
/ 20 ноября 2018

Команды пока официально не поддерживают Bot Framework 4.0.

...