Telegram Windows CLI

I’ve been looking for a cross platform messaging solution that has an open API so that I can integrate this into IntelliAlert. This should save me a few pennies when I need to send SMS messages to multiple users to alert them of issues.

This would also be handy for group chats, I often want to inform multiple users of an event and allow them to discuss it between themselves.

I decided on Telegram, it has an API and it has pre-written C# dlls ( for this API.

My requirements are simple, I want to be able to send text and media to individual users or to a group of users. Note that I am happy to create the group on my phone and add the necessary users myself.

I want to be able to call SendMessageToUser and SendMessageToGroup from a command line so I don’t have to worry about whether the call is being made by a desktop application or a Windows service.

So the coding began, I downloaded the Nuget TLSharp package and started playing around.

First thing I needed to do was authorise my app to use my phone number, this requires a UI element since it’s interactive, you request authorisation, you get a message in your Telegram and you send this back via the UI.

Once I have authorised the TLSharp dlls create a session.dat file in the same directory as the executable which can be used to login after the initial authorisation has take place.

Now that I’m authorised I just need to take my command line parameters and fire off either of the following functions.

SendMessageToGroup(string GroupName, string Message, string Media, string MediaTitle)
SendMessageToUser(string ContactPhone, string Message, string Media, string MediaTitle)

I now have a stable executable that I can call like this …

Telegram.exe --groupname=TestGroup --contactphone= --media= --mediatitle= --message=Hello world!!

This allows me to send messages to a group or to individuals based on my requirements it also allows me to call the CLI from a service (after initial authorisation).

My days of paying for Twilio are numbered as soon as I can convince all my clients to download Telegram on their smartphones.

So, what do you think ?