microsoft / BotFramework-Services

Microsoft Bot Framework Services
Creative Commons Attribution 4.0 International
38 stars 11 forks source link

[Telegram] Telegram channel sometimes doesn't receive landscape photos #106

Closed Sabatino78 closed 4 years ago

Sabatino78 commented 5 years ago

I've created a bot using the v 4.0 framework and configured the telegram channel. The bot code:

            if (turnContext.Activity.Attachments != null &&
                turnContext.Activity.Attachments.Count > 0)
                await turnContext.SendActivityAsync(MessageFactory.Text("i've received an attachment"), cancellationToken);
            else
                await turnContext.SendActivityAsync(MessageFactory.Text("i've received a text"), cancellationToken);

If i send a text the bot works correctly, if i send a portrait photo (vertical) it work correctly also, if i send a landscape photo (horizontal) the bot seems don't receive nothing. The error is present if i write to the bot with the phone app and also if i use the telegram website as client. On the channels error page i see "7/8/2019, 15:07:00 | Sequence contains no matching element"

Can you help me?

jameslew commented 5 years ago

Hi Sabatino. Certainly there's nothing specific we're doing with respect to image aspect ratio. Is it a specific landscape photo that isn't working? Is it a larger file or different type than the portrait item you're working with?

Sabatino78 commented 5 years ago

The problem occurs for any type of image, the problem seems to be related to the aspect ratio. When the width> height the bot does not receive anything.

I'll give you a sample:

stevkan commented 5 years ago

@Sabatino78, both of these links point to the same file. Can you update the link to the landscape image that isn't working?

Sabatino78 commented 5 years ago

Sorry, this is the link to the bad photo: https://safilenetasiubot.blob.core.windows.net/public/ko.jpeg

There is a method to enable and/or see the log from the Telegram channel configured on the bot?

stevkan commented 5 years ago

I haven't come across an option (yet) for observing Telegram logs. Should I notice anything I will post that here.

I have successfully repro'd the issue. Initial tests seem to indicate some sort of image ratio as the limiting factor. As the image approaches parity in height and width from a portrait to a landscape layout, the image then gets "lost". That is to say, it appears to upload but there is no response returned from Telegram. The size of the image doesn't seem to matter.

I will keep you posted.

stevkan commented 5 years ago

I performed some further testing around uploading images. The BF connector is throwing an exception when an image is sent that exceeds an aspect ratio between 0.79785 and 0.79882, width to height.

I tested image sizes of 512x512, 1024x1024, and 2048x2048 down to 409x512, 818x1024, 1636x2048, respectively. The exception throws continuously until the aspect ratio dips below the above range. Reducing the width by one pixel more (e.g. 408) results in the image/message being received correctly by the connector/bot.

The exception logged comes from Kusto.

{
    "timestamp": 2019 - 08 - 13T19: 06: 55.250693Z,
        "name": Bot generated exception,
            "conv_id": ,
    "cloud_RoleInstance": RD0003FF410292,
        "customDimensions": {
        "SerializationTimeMs": "0.0024",
            "Bot ID": "xxxxx",
                "Operation ID": "Telegram message failed",
                    "Exception": "{\r\n  \"ClassName\": \"System.InvalidOperationException\",\r\n  \"Message\": \"Sequence contains no matching element\",\r\n  \"Data\": null,\r\n  \"InnerException\": null,\r\n  \"HelpURL\": null,\r\n  \"StackTraceString\": \"   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source, Func`2 predicate)\\r\\n   at TelegramChannel.TelegramMessageMapper.<AttachPhoto>d__19.MoveNext() in D:\\\\a\\\\1\\\\s\\\\Channels\\\\TelegramChannel\\\\TelegramMessageMapper.cs:line 402\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\\r\\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\\r\\n   at TelegramChannel.TelegramMessageMapper.<ToMessageActivity>d__7.MoveNext() in D:\\\\a\\\\1\\\\s\\\\Channels\\\\TelegramChannel\\\\TelegramMessageMapper.cs:line 140\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\\r\\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\\r\\n   at TelegramChannel.TelegramMessageMapper.<ToMessageActivity>d__6.MoveNext() in D:\\\\a\\\\1\\\\s\\\\Channels\\\\TelegramChannel\\\\TelegramMessageMapper.cs:line 110\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\\r\\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\\r\\n   at TelegramChannel.Controllers.TelegramController.<HandleMessageV3>d__1.MoveNext() in D:\\\\a\\\\1\\\\s\\\\Channels\\\\TelegramChannel\\\\Controllers\\\\TelegramController.cs:line 158\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\\r\\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\\r\\n   at TelegramChannel.Controllers.TelegramController.<>c__DisplayClass0_1.<<Post>b__0>d.MoveNext() in D:\\\\a\\\\1\\\\s\\\\Channels\\\\TelegramChannel\\\\Controllers\\\\TelegramController.cs:line 111\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\\r\\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\\r\\n   at Intercom.Models.RedisExtensions.<DoOnce>d__8.MoveNext() in D:\\\\a\\\\1\\\\s\\\\Intercom.Models\\\\RedisExtensions.cs:line 137\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\\r\\n   at Intercom.Models.RedisExtensions.<DoOnce>d__8.MoveNext() in D:\\\\a\\\\1\\\\s\\\\Intercom.Models\\\\RedisExtensions.cs:line 155\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\\r\\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\\r\\n   at TelegramChannel.Controllers.TelegramController.<Post>d__0.MoveNext() in D:\\\\a\\\\1\\\\s\\\\Channels\\\\TelegramChannel\\\\Controllers\\\\TelegramController.cs:line 91\",\r\n  \"RemoteStackTraceString\": null,\r\n  \"RemoteStackIndex\": 0,\r\n  \"ExceptionMethod\": \"8\\nFirst\\nSystem.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\\nSystem.Linq.Enumerable\\nTSource First[TSource](System.Collections.Generic.IEnumerable`1[TSource], System.Func`2[TSource,System.Boolean])\",\r\n  \"HResult\": -2146233079,\r\n  \"Source\": \"System.Core\",\r\n  \"WatsonBuckets\": null\r\n}"
    },
    "customMeasurements": ,
}
jameslew commented 5 years ago

Fascinating bug. @stevekan Has this been reflected in the internal service bug db yet? If not i will enter.

stevkan commented 5 years ago

@jameslew, a bug was already created internally. I updated the item to reflect the above findings.

tsuwandy commented 5 years ago

@jameslew, @craigjensen shall we close this then as bug was created already?

jameslew commented 5 years ago

I'm keeping this item open until it's fixed by a developer; however I am monitoring.

arturl commented 4 years ago

Fix available -- should be deployed before 10/18

congysu commented 4 years ago

@arturl can you please confirm this is deployed? thanks.

arturl commented 4 years ago

The deployment just completed, the issue is fixed.