botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

[Skype] EndConversation fails with "Unknown activity type" exception

Open martinoss opened this issue 9 years ago • 19 comments

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 😉

martinoss avatar Oct 05 '17 14:10 martinoss

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

IoTGirl avatar Oct 06 '17 17:10 IoTGirl

Please let us know if this was not resolved

JasonSowers avatar Oct 31 '17 22:10 JasonSowers

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

Thanks a lot!

xjose97x avatar Nov 23 '17 15:11 xjose97x

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

IoTGirl avatar Nov 23 '17 18:11 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" [email protected]:

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 .

martinoss avatar Nov 23 '17 20:11 martinoss

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

xjose97x avatar Nov 23 '17 22:11 xjose97x

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

IoTGirl avatar Nov 26 '17 07:11 IoTGirl

@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)

xjose97x avatar Dec 05 '17 01:12 xjose97x

Bumping. This problem still occurs...

methical avatar Mar 08 '18 10:03 methical

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 avatar Mar 14 '18 16:03 pconnell99

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

xjose97x avatar Mar 14 '18 16:03 xjose97x

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

pconnell99 avatar Mar 14 '18 16:03 pconnell99

Another one happening here...

Any ETA for the fix?

   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)

softwaresicario avatar Mar 23 '18 00:03 softwaresicario

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 avatar Apr 19 '18 15:04 Amintasn

@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 avatar Apr 24 '18 06:04 martinoss

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

Amintasn avatar Apr 24 '18 18:04 Amintasn

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

oflahero avatar Jun 07 '18 13:06 oflahero

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

JasonSowers avatar Jun 28 '18 15:06 JasonSowers

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

rcc-peters avatar Sep 21 '18 00:09 rcc-peters