VL.Telegram

,

hey there,

i’m working on a new version of the telegram contribution, this time as VL-based nodes.

basic functionality is there already but some issues remain. will post them as soon as these could be adressed. stay tuned…

2 Likes

question to the devs:

i’m fighting with exception handling in VL: the communication between the base library and the telegram servers happens mostly by async function calls, which internally create HTTP requests. when the request return errors (e.g. 404) an exception is thrown.
executing the calling function from within a try-region does not catch the exception (maybe because it happens async?). is there a way to catch these exceptions?

------------------------------------------------------------------------------
Exception class: EClrException
Exception message: Response status code does not indicate success: 404 (Not Found).
Exception address: 0000000000000000
------------------------------------------------------------------------------
System.Net.Http.HttpRequestException: Response status code does not indicate success: 404 (Not Found).
   at VL.Core.RuntimeGraph.HandleException(UInt32 rootId) in C:\BuildAgent\work\95074898639d5736\public-vl\VL.Core\src\RuntimeGraph.cs:line 123
   at VVVV.VL.Hosting.NodePlugin.Evaluate(Int32 spreadMax) in C:\BuildAgent\work\95074898639d5736\vvvv50\VVVV.VLIntegration\src\NodePlugin.cs:line 0

if you use Task.Result (which is blocking) the exception should be thrown in the region.

then wrap everything in an AsyncTask region to get the async behavior back…

thanks @tonfilm . this way it is possible to catch the exception. unfortunately i’m loosing the info on what kind of exception was causing the troubles as the try-region only outputs a string like “one or more errors caused the exception”.

on the other hand when not using an async region and using HoldLatestError it is possible to catch the cause but the exception is rethrown, which I’d like to prevent.

any idea how to get the type of exception and catch it also?

the TryCatch region has a catch operation inside, there you get the full .NET exception. note that this region has two layers inside, Try and Catch. you need to assign your nodes to one or the other.

i was looking into TryCatch already but i’m not sure how that region would help me, as the output of the Catch-layer has to be of the same data-type as the Try layer.

the only thing I could think of would be the creation of a new type (or tuple), wrapping type and some string to output it together, and unwrap it outside. this feels quite awkward as one part of this structure would always be empty - is there a more elegant way?

grafik
grafik

Well, it seems to do the trick. If there are more elegant solutions, please tell…

there should be a TryCatch with two outputs which saves you the tuple. or are you on beta36?

good idea, but anyways then i’m stuck with the single output from AsyncTask. so it seems the tuple is the way to go…

alright - first version to try is here:

VL.Telegram.0.0.1.zip (114.1 KB)

nuget is in the working…

2 Likes

Just tried this since the vvvv version doesn’t work with 38.1, and this does not either. all nodes red. Doesn’t work for me under 35.8 either, which the vvvv version does.

So is there no workable version for recent releases? Are there some dependencies I may be missing? Thanks @motzi for a very useful plugin, I miss it!

hey @mediadog, thanks for noting this and glad you like it. i did not have a look into this for quite some time now and unfortunately am quite busy atm. however, I do consider giving this an update as soon as time permits. sorry for leaving this in an unfinished state…

@mediadog - i just opened it up for a quick look. did you install all dependencies? vl.telegram menu->dependencies -> right click missing dependencies and install them.

this should solve our red node problem (just checked with alpha 38.2 but should be the same with b38.1). however, i could only connect to a bot but not send messages to it (and therefore send something back). this needs more investigation…

hey all,

some days ago I started working on an implementation of the Telegram.Bots library for gamma.
wanted to share my results and stumbled upon that post that I had totally forgotten :)

so here’s my take on this : https://github.com/sebescudie/VL.Telegram

i’d say things are working good here but could be improved (more on that later). for now, here’s what you can do :

  • send and receive text messages
  • send pictures (either from a file or from an SKImage)
  • send inline and reply keyboards
  • react to a user press on an inline keyboard

you can test it right away (might need to install the missing nuget) and dive in the help patches.

now, here’s what i would like to improve :

  • all send methods from the library are async (SendTextMessageAsync, SendPhotoAsync, etc) and they all output a Task<Message> (converted to Observable with ToObservable) that fires when the message has successfully been sent.
    since you don’t know in advance when the message is gonna be sent, my first take was to put those in an AsyncTask, but then you end up with an Observable<Observable<Message>> which does not make much sense to me.
    i ended up putting those in a cache region that’s triggered by the “force” pin when I wanna send the message : this works, after completion, the observable is triggered.
    is it the best way to go though? check the send images help patch to see what I mean.

  • one feature i wanted was the ability to send an image directly coming from an offscreen renderer. internally, the lib wants you to create a FileStream before uploading anything.
    what other options do I have other than creating a temporary file on the disk before sending it? is it safe to do it like so ?

    update : the node now uses MemoryStream internally, which allows to create a stream without having to create a temp file.

thanks in adavance for your pointers and feedback :)

cheerz !

2 Likes