public Message sendMessage(int intChatId, string strText) { if (intChatId < 1) { return null; } if (string.IsNullOrEmpty(strText)) { return null; } Request objRequest = new Request(Request.EnmFunction.SEND_MESSAGE); objRequest.addValue("chat_id", intChatId); objRequest.addValue("text", strText); Response objResponse = this.sentRequest(objRequest); if (objResponse == null) { return null; } return objResponse.getObjResult<Message>(); }
internal Response sentRequest(Request objRequest) { Console.WriteLine("Starting sending POST data to Telegram server."); if (objRequest == null) { Console.WriteLine("Invalid request."); return null; } HttpClient objHttpClient = new HttpClient(); HttpResponseMessage objResponse = objHttpClient.PostAsync(this.getUrlBot(objRequest.strFunctionName), objRequest.frm).Result; objHttpClient.Dispose(); string strResult = objResponse.Content.ReadAsStringAsync().Result; return new Response(strResult); }
public Update[] getUpdates(long intOffSet = 0, int intLimite = 100, int intTimeOut = 0) { Request objRequest = new Request(Request.EnmFunction.GET_UPDATES); objRequest.enmFunction = Request.EnmFunction.GET_UPDATES; objRequest.addValue("offset", intOffSet); objRequest.addValue("limit", intLimite); objRequest.addValue("timeout", intTimeOut); Response objResponse = this.sentRequest(objRequest); if (objResponse == null) { return null; } if (!objResponse.validate()) { return null; } return objResponse.getArrObjResult<Update>(); }
private void initializeBot() { Console.WriteLine("Starting the bot configurations."); Request objRequest = new Request(Request.EnmFunction.SET_WEB_HOOK); objRequest.enmFunction = Request.EnmFunction.SET_WEB_HOOK; objRequest.addValue("url", string.Empty); Response objResponse = TelegramServer.i.sentRequest(objRequest); if (!this.initializeBotValidate(objResponse.strResult)) { Console.WriteLine("Error on configure this bot."); return; } }