Botframework-sdk: [Skype] EndConversation fails with "Unknown activity type" exception

Created on 5 Oct 2017  Â·  19Comments  Â·  Source: microsoft/botframework-sdk

Bot Info

  • Bot handle:
  • App ID:
  • SDK Platform: .NET
  • SDK Version: 3.9.1
  • Active Channels: Skype, Facebook
  • Deployment Environment: Azure App Service

Issue Description

After a use case has been completed, we call context.EndConversation("end of conversation") to reset stack and conversation data.

  • In Facebook, it resets the stack and clears the data, and no exception occures => OK
  • In Skype, it resets the stack and clears the data, but an exception is thrown

"Unknown activity type"

Resulting in a "Sorry my bot code having an issue..." (btw, regardless I specified a custom message).

Code Example

Reproduction Steps

  1. Create a simple bot and call context.EndConversation("end of conversation");
  2. Deploy to skype and test

Expected Behavior

In skype, it should not throw an exception.

Actual Results

It throws an exception > "Unknown activity type"

Workaround

Placing that line in a try-catch block does not help because the event triggers a scorable. A workaround for me could be, duplicating this code and try-catch here, but I hope for a better suggestion or fix 😉

Most helpful comment

Thanks for the confirmation @martinoss and @xjose97x. I have pinged the Skype Bot folks again with a link to this issue.

All 19 comments

Hi @martinoss ,
I have escalated this to Skype Bot folks. Hope to get you something soon!
Sincerely,
IoTGirl

Please let us know if this was not resolved

@IoTGirl @JasonSowers I'm facing the same issue. Any update on this?

Thanks a lot!

Hi @xjose97x ,

It is our understanding that this issue is resolved. Is you issue exactly the same as what is documented above?

Sincere thanks,
IoTGirl

The problem is still here...

As workaround I implemented a modified EndOfConversation scorable where
skype will not receive that activity.

Am 23.11.2017 19:53 schrieb "IoTGirl" notifications@github.com:

Hi @xjose97x https://github.com/xjose97x ,

It is our understanding that this issue is resolved. Is you issue exactly
the same as what is documented above?

Sincere thanks,
IoTGirl

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/Microsoft/BotBuilder/issues/3576#issuecomment-346682740,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ACd9Jkhu-ATlruXl1ZkR63HL3i9Kn-BHks5s5b8-gaJpZM4PvKO6
.

@IoTGirl I'm facing the exact same issue, yes.

Thanks for the confirmation @martinoss and @xjose97x. I have pinged the Skype Bot folks again with a link to this issue.

@IoTGirl do you know what's the status with this issue?
I did as @martinoss and implemented the EndOfConversation scorable as well to prevent this issue, however would be nice to know when it would be safe to remove (thinking for production environments)

Bumping. This problem still occurs...

I'm getting this with an MS Teams based bot, no Skype integration AFAIK. There is an error in the logs when it runs (it still responds but logs this in the 'Channels' errors as 'Unknown Activity Type').

Error: POST to 'https://smba.trafficmanager.net/emea-client-ss.msg/v3/conversations/<redacted in case it's PII>thread.skype%3Bmessageid%3D1521043292464/activities/1521043292464' failed: [400] Bad Request

It mentions Skype, but I have no Skype integration. Why is it trying to talk to Skype?

@pconnell99 I believe Microsoft Teams uses some skype endpoints for message delivering.

Ah, ok. Still get the error though. May be my implementation, not sure though - documentation (as with many projects MS manage) is poor.

Another one happening here...

Any ETA for the fix?

2018-03-22T20:10:12.60-0400 [APP/PROC/WEB/0] ERR Error: POST to 'https://smba.trafficmanager.net/apis/v3/conversations/HIDDENCONVERSATIONIDHERE/activities' failed: [400] Bad Request 2018-03-22T20:10:12.60-0400 [APP/PROC/WEB/0] ERR at Request._callback (/home/vcap/app/node_modules/botbuilder/lib/bots/ChatConnector.js:559:46) 2018-03-22T20:10:12.60-0400 [APP/PROC/WEB/0] ERR at Request.self.callback (/home/vcap/app/node_modules/request/request.js:186:22) 2018-03-22T20:10:12.60-0400 [APP/PROC/WEB/0] ERR at emitTwo (events.js:106:13) 2018-03-22T20:10:12.60-0400 [APP/PROC/WEB/0] ERR at Request.emit (events.js:191:7) 2018-03-22T20:10:12.60-0400 [APP/PROC/WEB/0] ERR at Request.<anonymous> (/home/vcap/app/node_modules/request/request.js:1163:10) 2018-03-22T20:10:12.60-0400 [APP/PROC/WEB/0] ERR at emitOne (events.js:96:13) 2018-03-22T20:10:12.60-0400 [APP/PROC/WEB/0] ERR at Request.emit (events.js:188:7) 2018-03-22T20:10:12.60-0400 [APP/PROC/WEB/0] ERR at IncomingMessage.<anonymous> (/home/vcap/app/node_modules/request/request.js:1085:12) 2018-03-22T20:10:12.60-0400 [APP/PROC/WEB/0] ERR at IncomingMessage.g (events.js:292:16) 2018-03-22T20:10:12.60-0400 [APP/PROC/WEB/0] ERR at emitNone (events.js:91:20) 2018-03-22T20:10:12.60-0400 [APP/PROC/WEB/0] ERR at IncomingMessage.emit (events.js:185:7) 2018-03-22T20:10:12.60-0400 [APP/PROC/WEB/0] ERR at process._tickDomainCallback (internal/process/next_tick.js:128:9)

Also facing the same issue. Can any one pls share a code snippet of the EndOfConversation scorable workaround previously mentioned in this thread? Thx

@Amintasn
This is what I did:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Bot.Builder.Dialogs.Internals;
using Microsoft.Bot.Builder.Scorables;
using Microsoft.Bot.Builder.Scorables.Internals;
using Microsoft.Bot.Connector;
using Microsoft.Bot.Builder.Dialogs;
using MyBot.Api.Channels;

namespace MyBot.Api.Events
{
    /// <summary>
    /// This event represents the end of the conversation.  It is initiated by <see cref="Extensions.EndConversation(IDialogContext, string)"/>
    /// and propagates as an event in the stack scorable process to allow interception.
    /// </summary>
    /// <remarks>
    /// This is an adapted version of the original implementation. It skips sending an end of conversation event to skype, because
    /// skype will throw an error.
    /// https://github.com/Microsoft/BotBuilder/issues/3576
    /// See original implementation:
    /// https://github.com/Microsoft/BotBuilder/blob/master/CSharp/Library/Microsoft.Bot.Builder/Dialogs/EndConversation.cs
    /// </remarks>
    public sealed class BetterEndConversationEvent
    {
        /// <summary>
        /// Code selected from <see cref="BetterEndOfConversationCodes"/> 
        /// </summary>
        public string Code { get; }

        /// <summary>
        /// Construct the <see cref="BetterEndConversationEvent"/>.
        /// </summary>
        /// <param name="code">Code selected from <see cref="EndOfConversationCodes"/>.</param>
        public BetterEndConversationEvent(string code)
        {
            this.Code = code;
        }

        /// <summary>
        /// Construct the scorable used to handle the <see cref="BetterEndConversationEvent"/>.
        /// </summary>
        /// <returns>The constructed scorable.</returns>
        public static IScorable<IResolver, double> MakeScorable()
        {
            var scorable =
                Actions.Bind(async (BetterEndConversationEvent e, IDialogStack stack, IBotToUser botToUser, IBotData data, CancellationToken token) =>
                {
                    stack.Reset();

                    data.ConversationData.Clear();
                    data.PrivateConversationData.Clear();

                    var end = botToUser.MakeMessage();

                    // https://github.com/Microsoft/BotBuilder/issues/3576
                    if (!end.IsSkype()) // <= I used a helper here (extension method). Just check the activity channel against "skype"
                    {
                        end.Type = ActivityTypes.EndOfConversation;
                        end.AsEndOfConversationActivity().Code = e.Code;

                        await botToUser.PostAsync(end, token);
                    } 
                })
                .Normalize();

            return scorable;
        }
    }

    public static partial class Extensions
    {
        private static readonly ResumeAfter<IEventActivity> AfterReset = (context, result) => Task.CompletedTask;

        /// <summary>
        /// Initiate an <see cref="BetterEndConversationEvent"/> to reset the conversation's state and stack and send an
        /// <see cref="ActivityTypes.EndOfConversation"/> to the Connector.
        /// </summary>
        public static void BetterEndConversation(this IDialogContext context, string code)
        {
            var activity = new Activity(ActivityTypes.Event) { Value = new BetterEndConversationEvent(code) };
            context.Post(activity, AfterReset);            
        }
    }
}

Dont forget to setup DI for this in your bootstrapping module:

// Scorable implementing a more stable version "end conversation" (Skype bug aware)
builder
    .RegisterInstance(BetterEndConversationEvent.MakeScorable())
    .As<IScorable<IResolver, double>>()
    .SingleInstance();

@martinoss Thanks a lot for the help! It worked very well. Cheers

@martinoss Seconding the love. Thanks for sharing, it was a puzzle tracking this one down (as my logging only detected a BotFramework 'BadRequest'. :) )

Please open a new issue if you are still experiencing problems with this.

issue still occuring, possible related bug https://github.com/Microsoft/BotBuilder/issues/4718

Was this page helpful?
0 / 5 - 0 ratings