Skip to content

Instantly share code, notes, and snippets.

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 SebastianGaud/7b2889012bd5552942d509b93ea6f652 to your computer and use it in GitHub Desktop.
Save SebastianGaud/7b2889012bd5552942d509b93ea6f652 to your computer and use it in GitHub Desktop.
Retrieve Chat Id from getUpdates and send a Message to the first recipient
public static void Main(string[] args)
{
List<Result> result = MakeRequest().Result;
SendMessage(result);
Console.Read();
}
public static async void SendMessage(List<Result> result)
{
TelegramBotClient client = new TelegramBotClient( ApiKey );
Result res = result[0];
Console.WriteLine( res.Message.From.Id );
var t = await client.SendTextMessageAsync( res.Message.From.Id , "Ciao pelandrone!" );
Console.WriteLine( t.From.FirstName );
}
public static async Task<List<Result>> MakeRequest()
{
HttpClient client = new HttpClient();
client.BaseAddress = new Uri( ApiEndPoint + ApiKey + "/" );
// Add an Accept header for JSON format.
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue( "application/json" ) );
// List data response.
HttpResponseMessage response = client.GetAsync( client.BaseAddress + Command.GetUpdates ).Result; // Blocking call!
if (!response.IsSuccessStatusCode)
{
Console.WriteLine("{0} ({1})", response.StatusCode, response.ReasonPhrase);
throw new Exception();
}
else
{
string data = await response.Content.ReadAsStringAsync();
Console.WriteLine(data);
Response result = JsonConvert.DeserializeObject<Response>(data);
return result.Result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment