Last active
August 11, 2017 12:41
-
-
Save dipievil/20184aea515a1a7e6fce09720dea4020 to your computer and use it in GitHub Desktop.
C# class to send notification to Telegram via Integram
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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