Skip to content

Instantly share code, notes, and snippets.

@dipievil
Last active August 11, 2017 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dipievil/20184aea515a1a7e6fce09720dea4020 to your computer and use it in GitHub Desktop.
Save dipievil/20184aea515a1a7e6fce09720dea4020 to your computer and use it in GitHub Desktop.
C# class to send notification to Telegram via Integram
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace IntegramConn
{
public class IntegramService
{
/// <summary>
/// Main class to send notification to Telegram
/// See Integram.org for more information
/// Use markdown syntax for formatting message
/// </summary>
/// <param name="author">Sender´s name</param>
/// <param name="message">Message to send</param>
private static void NotifyTelegram(string author, string message)
{
const string CHANNEL_KEY = "ci8tA2mq4Q1"; //CHANGE TO YOUR OWN CHANNEL KEY
string urlChannel = "https://integram.org/" + CHANNEL_KEY;
string messageJSON = "{\"text\":\"*" + author + "*: " + message + "\"}";
WebClient clientTelegram = new WebClient();
var resposta = clientTelegram.UploadData(urlChannel, "POST", Encoding.UTF8.GetBytes(messageJSON));
}
/// <summary>
/// Very, very, very simple class to send the notification
/// </summary>
/// <param name="author">Sender´s name</param>
/// <param name="message">Message to send</param>
/// <returns></returns>
public bool SendAlert(string author, string message)
{
bool returnStatus = false;
try
{
NotifyTelegram(author, message);
returnStatus = true;
}
catch
{
returnStatus = false;
}
return returnStatus;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment