How to use Telegram API in C# to send a message

how to send message in telegram group
telegram api c#
telegram api send message
python-telegram bot send message to channel
telegram bot send message to group
telegram api send message to phone number
telegram java api send message
telegram.bot example

I want use Telegram API in C# for send a simple message to a number. I found some lib's on GitHub but I am not able to use them.

Can anyone give a simple code ? Can I simply make HTTP calls ?

  1. Install-Package Telegram.Bot
  2. Create a bot using the botfather
  3. get the api key using the /token command (still in botfather)
  4. use this code:

var bot = new Api("your api key here"); var t = await bot.SendTextMessage("@channelname or chat_id", "text message");

You can now pass a channel username (in the format @channelusername) in the place of chat_id in all methods (and instead of from_chat_id in forwardMessage). For this to work, the bot must be an administrator in the channel.

https://core.telegram.org/bots/api

Send Telegram messages from C# – Tutorials, tips&tricks, snippets.., Since I'm a developer I love the simple APIs of this app and how easy is, for example, create a bot and use it for send messages. First of all, you  To send a Telegram message in C#, do this: Copy the following source code to the main class in your Console Application in Visual Studio. Customize the TODO lines: Specify your gateway instance ID on line 10. Specify your client ID and secret on lines 11 and 12. Specify your target recipient and message on line 19.

use this code :) with https://github.com/sochix/TLSharp

 using TeleSharp.TL;
 using TLSharp;
 using TLSharp.Core;

 namespace TelegramSend
 {

    public partial class Form1 : Form
    {
      public Form1()
     {
         InitializeComponent();
     }


    TelegramClient client;

    private async void button1_Click(object sender, EventArgs e)
    {
        client = new TelegramClient(<your api_id>,  <your api_key>);
        await client.ConnectAsync();
    }

    string hash;

    private async void button2_Click(object sender, EventArgs e)
    {
        hash = await client.SendCodeRequestAsync(textBox1.Text);
        //var code = "<code_from_telegram>"; // you can change code in debugger


    }

    private async void button3_Click(object sender, EventArgs e)
    {
        var user = await client.MakeAuthAsync(textBox1.Text, hash, textBox2.Text);
    }

    private async void button4_Click(object sender, EventArgs e)
    {

        //get available contacts
        var result = await client.GetContactsAsync();

        //find recipient in contacts
        var user = result.users.lists
            .Where(x => x.GetType() == typeof(TLUser))
            .Cast<TLUser>()
            .Where(x => x.first_name == "ZRX");
        if (user.ToList().Count != 0)
        {
            foreach (var u in user)
            {
                if (u.phone.Contains("3965604"))
                {
                    //send message
                    await client.SendMessageAsync(new TLInputPeerUser() { user_id = u.id }, textBox3.Text);
                }
            }
        }

    }
 }}

How to send Telegram Messages in C#, Using the WhatsMate Telegram Gateway REST API article shows you how to send a Duration: 4:14 Posted: Sep 9, 2016 Steps for creating a Telegram bot. 1. Find, and start a conversation with the BotFather. If you’ve never had a conversation with @BotFather before, just bring up your Contacts and search for him. Then add him as a contact and start a conversation with him.

Here is the easiest way I found so far. I found it here, thanks to Paolo Montalto https://medium.com/@xabaras/sending-a-message-to-a-telegram-channel-the-easy-way-eb0a0b32968

After creating a Telegram bot via BotFather and getting your destination IDs via https://api.telegram.org/bot[YourApiToken]/getUpdates you can send a message to your IDs by issuing an HTTP GET request to Telegram BOT API using the following URL https://api.telegram.org/bot[YourApiToken]/sendMessage?chat_id=[DestitationID]&text=[MESSAGE_TEXT]

Details on a simple way to create a bot and get IDs may be found here: https://programmingistheway.wordpress.com/2015/12/03/send-telegram-messages-from-c/

You can test those url strings even directly in browser. Here is a simple method I use in C# to send messages, without dependency on any bot api related dll and async calls complication:

using System.Net;
...
public string TelegramSendMessage(string apilToken, string destID, string text)
{
string urlString = $"https://api.telegram.org/bot{apilToken}/sendMessage?chat_id={destID}&text={text}";

WebClient webclient = new WebClient();

return webclient.DownloadString(urlString);
}

How to send a message to a public Telegram channel by php , How can I send message to Telegram channel in PHP? Instructions are available on the official site. To send a Telegram group message from your C# application, do this: Create a New Group from your Telegram client. Add the secret gateway to the group. (You can add other people too!) Give your group a unique and creative name.

1-first create a channel in telegram (for example @mychanel)

2-create a telegram bot (for example @myTestBot) and get api token for next step

3-add @myTestBot to your channel(@mychanel) as administrator user

4-use below code for send message:

   var bot = new TelegramBotClient("api_token_bot");
        var s = await bot.SendTextMessageAsync("@mychanel", "your_message");

Sending a message to a Telegram channel the easy way, Today we'll se by practical examples how to send a message to a Telegram channel. https://api.telegram.org/bot[BOT_API_KEY]/sendMessage?chat_id=[ Do what you want with data } downloadTask.resume(). C# string urlString  Learn how to create a Telegram Bot and get a bot token. See how to add that bot to a Telegram group, and how to find the chat ID. Full demo on on how to use your bot token and chat ID to send

Good article to start: How-To: Send messages to Telegram from C#

TLSharp is basic implementation of Telegram API on C#. See it here https://github.com/sochix/TLSharp

Send Message To Telegram using API in asp.net / c#, Hello All, I wanna Send Message to telegram number using asp.net/c#! like how to use telegram api in asp.net/c# to send Message. Receive SMS with Telegram App. Send SMS to the Telegram app from cell phone. Bot will be forwarding all incoming Text messages to your App channel. Telegram API bot with PHP SendMessage.

Create basic Messaging Telegram Bot with c# .net, In this video I show you how to create a basic telegram bot that sends messages to the user Duration: 8:33 Posted: Aug 29, 2017 The Bot API allows you to easily create programs that use Telegram messages for an interface. The Telegram API and TDLib allow you to build your own customized Telegram clients. You are welcome to use both APIs free of charge.

[SOURCE CODE] Telegram Bot auto send text message C# Winform , NET Client for robot Telegram Bot API. The Bot API is an HTTP-based interface created for Duration: 7:25 Posted: Aug 26, 2019 TLSharp is an unofficial Telegram client library implemented in C#, you can try to use it to send data to Telegram users. Besides, this SO thread discussed " How to use Telegram API in C# to send a message ", please refer to it.

C# Telegram Bot API, Here is my telegram bot c# codes (a console application) : using System; using System.IO; using C# Telegram Bot API - How send a link & open it on client #​166. Closed Message; if (message == null || message.Type != To prevent spam, bots cannot initiate a chat, so we need to send it a message to enable the bot to message us back. We will read this message via the Telegram API to get the chat_id in the next step.

Comments
  • You should put more effort into your question if you want anyone to help you. Read the How to ask a good question guide.
  • problems about using github projects is very strange when we download and use very easy from other sites like codeplex or codeproject but android project and some c# libraries in github and relations for required libraries is very hard things for students. and starter users in start using from github
  • What did you eventually use for your project?
  • I'm trying your code, but it doesn't do anything.. I've created a bot, have I to do something else to use it?
  • You confused guy with you library for Telegram Bot Api. He wants to use Telegram API
  • The subject of the question is about Telegram API not Telegram Bot API.
  • I get this error: Invalid token format . My token is such as "3bd8d2839afbb0ba2cf566678b7b0bc2"
  • I can not install TLSharp using Nuget because module DotNetZip doesn't compatible with Android
  • Very neat answer, no need to install package
  • The subject of the question is about Telegram API not Telegram Bot API.
  • This is a good answer for some use cases e.g. automated publishing without having to create an app
  • You fail at giving a code sample. That's what the OP wants. See how to answer to learn how to write a good answer.
  • These examples are horrible out of date. Lot's of code changes, change from non-async methods to async tasks, no context given.