Change telegram chatid from int32 to string

Change telegram chatid from int32 to string (#11649)
This commit is contained in:
Theo Arends 2021-04-10 15:04:50 +02:00
parent 4426693170
commit 0599041760
1 changed files with 6 additions and 6 deletions

View File

@ -62,11 +62,11 @@ static const uint8_t Telegram_Fingerprint[] PROGMEM = USE_TELEGRAM_FINGERPRINT;
typedef struct {
String text;
String chat_id;
// String from_first_name;
// String from_last_name;
// uint32_t from_id = 0;
uint32_t update_id = 0;
int32_t chat_id = 0;
} TelegramMessage;
struct {
@ -233,12 +233,12 @@ void TelegramGetUpdates(uint32_t offset) {
// Telegram.message[i].from_id = result["message"].getObject()["from"].getObject()["id"].getUInt();
// Telegram.message[i].from_first_name = result["message"].getObject()["from"].getObject()["first_name"].getStr();
// Telegram.message[i].from_last_name = result["message"].getObject()["from"].getObject()["last_name"].getStr();
Telegram.message[i].chat_id = result["message"].getObject()["chat"].getObject()["id"].getUInt();
Telegram.message[i].chat_id = result["message"].getObject()["chat"].getObject()["id"].getStr();
Telegram.message[i].text = result["message"].getObject()["text"].getStr();
}
Telegram.next_update_id = Telegram.message[i].update_id +1; // Write id of last read message
AddLog_P(LOG_LEVEL_DEBUG_MORE, PSTR("TGM: Parsed update_id %d, chat_id %d, text \"%s\""), Telegram.message[i].update_id, Telegram.message[i].chat_id, Telegram.message[i].text.c_str());
AddLog_P(LOG_LEVEL_DEBUG_MORE, PSTR("TGM: Parsed update_id %d, chat_id %s, text \"%s\""), Telegram.message[i].update_id, Telegram.message[i].chat_id.c_str(), Telegram.message[i].text.c_str());
}
} else {
// AddLog(LOG_LEVEL_DEBUG, PSTR("TGM: No new messages"));
@ -248,7 +248,7 @@ void TelegramGetUpdates(uint32_t offset) {
}
}
bool TelegramSendMessage(int32_t chat_id, String text) {
bool TelegramSendMessage(String chat_id, String text) {
AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("TGM: sendMessage"));
if (!TelegramInit()) { return false; }
@ -256,7 +256,7 @@ bool TelegramSendMessage(int32_t chat_id, String text) {
bool sent = false;
if (text != "") {
String _token = SettingsText(SET_TELEGRAM_TOKEN);
String command = "bot" + _token + "/sendMessage?chat_id=" + String(chat_id) + "&text=" + UrlEncode(text);
String command = "bot" + _token + "/sendMessage?chat_id=" + chat_id + "&text=" + UrlEncode(text);
String response = TelegramConnectToTelegram(command);
// AddLog_P(LOG_LEVEL_DEBUG_MORE, PSTR("TGM: Response %s"), response.c_str());
@ -440,7 +440,7 @@ void CmndTmSend(void) {
if (XdrvMailbox.data_len > 0) {
String message = XdrvMailbox.data;
String chat_id = SettingsText(SET_TELEGRAM_CHATID);
if (!TelegramSendMessage(chat_id.toInt(), message)) {
if (!TelegramSendMessage(chat_id, message)) {
ResponseCmndFailed();
return;
}