/// <summary> /// 搜尋Telegram機器人被加入的 群組或個人ID /// </summary> public List <GetUpDate> Serch_TelegramID() { List <GetUpDate> GetUpDates = null; try { var client = new RestClient("https://api.telegram.org/bot" + Telegram_HTTP_API + "/getUpdates?"); client.Timeout = -1; var request = new RestRequest(Method.GET); request.AlwaysMultipartFormData = true; IRestResponse response = client.Execute(request); GetUpDates = new List <GetUpDate>(); JObject jsondatas = JsonConvert.DeserializeObject <JObject>(response.Content); for (int Index = 0; Index < jsondatas["result"].Count(); Index++) { JObject jsondata = JsonConvert.DeserializeObject <JObject>(jsondatas["result"][Index].ToString()); if (jsondata["message"] != null) { GetUpDate getUpdate = JsonConvert.DeserializeObject <GetUpDate>($"{jsondata["message"]["chat"]}"); if (!GetUpDates.Exists(g => g.id == getUpdate.id)) { GetUpDates.Add(getUpdate); } } } return(GetUpDates); } catch (Exception ex) { Log.Error(ex, $"Telegram機器人 API網址錯誤 API網址: {Telegram_HTTP_API}"); return(GetUpDates); } }
/// <summary> /// 搜尋Telegram機器人被加入的 群組或個人ID /// </summary> public void Serch_TelegramID() { try { var client = new RestClient($"https://api.telegram.org/bot{Telegram_HTTP_API}/getUpdates?"); client.Timeout = -1; var request = new RestRequest(Method.GET); request.AlwaysMultipartFormData = true; IRestResponse response = client.Execute(request); JObject jsondatas = JsonConvert.DeserializeObject <JObject>(response.Content); for (int Index = 0; Index < jsondatas["result"].Count(); Index++) { JObject jsondata = JsonConvert.DeserializeObject <JObject>(jsondatas["result"][Index].ToString()); GetUpDate getUpdate = JsonConvert.DeserializeObject <GetUpDate>(jsondata["message"]["chat"].ToString()); GetUpDates.Add(getUpdate); } } catch (Exception ex) { Log.Error(ex, $"Telegram機器人 API網址錯誤 API網址: {Telegram_HTTP_API}"); } }