Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

3.5K
Views
Cómo usar la API de Telegram en C# para enviar un mensaje

Quiero usar la API de Telegram en C# para enviar un mensaje simple a un número. Encontré algunas librerías en GitHub pero no puedo usarlas.

¿Alguien puede dar un código simple? ¿Puedo simplemente hacer llamadas HTTP?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

  1. Paquete de instalación Telegram.Bot
  2. Crea un bot usando el botfather
  3. obtenga la clave api usando el comando /token (todavía en botfather)
  4. usa este código:
 var bot = new Api("your api key here"); var t = await bot.SendTextMessage("@channelname or chat_id", "text message");

Ahora puede pasar un nombre de usuario de canal (en el formato @channelusername) en lugar de chat_id en todos los métodos (y en lugar de from_chat_id en forwardMessage). Para que esto funcione, el bot debe ser administrador en el canal.

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

over 4 years ago · Santiago Trujillo Report

0

Aquí está la forma más fácil que encontré hasta ahora. Lo encontré aquí, gracias a Paolo Montalto https://medium.com/@xabaras/sending-a-message-to-a-telegram-channel-the-easy-way-eb0a0b32968

Después de crear un bot de Telegram a través de BotFather y obtener sus ID de destino a través de https://api.telegram.org/bot[YourApiToken]/getUpdates , puede enviar un mensaje a sus ID emitiendo una solicitud HTTP GET a Telegram BOT API usando lo siguiente URL https://api.telegram.org/bot[YourApiToken]/sendMessage?chat_id=[DestitationID]&text=[MESSAGE_TEXT]

Los detalles sobre una forma sencilla de crear un bot y obtener identificaciones se pueden encontrar aquí: https://programmingistheway.wordpress.com/2015/12/03/send-telegram-messages-from-c/

Puede probar esas cadenas de URL incluso directamente en el navegador. Aquí hay un método simple que uso en C # para enviar mensajes, sin depender de ninguna complicación de llamadas asincrónicas y dll relacionadas con la API de bot:

 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); }
over 4 years ago · Santiago Trujillo Report

0

usa este código :) con 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); } } } } }}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!