Problem initializing the Telegram bot (SOLVED)

But on telegram will I have to create a new bot? For this I did not expect. Will I have to shut down my current bot? What about the CHAT_ID ?

The bot is already created, I have you his @ in the post#79
Search it on telegram and click on "start" to begin the conversation

You don't have to delete your bot of course, but for now we will use mine so you can copy paste the result coming from the monitor of the arduino without editing the token (since it's the mine, i know it so you don't have to hide from me)

Your chat_id doesn't change, so it's still the same!

I think I did it correctly.

I commented out these two lines in the code in an attempt to relieve memory. Whatnot. Everything is valid. It was a first useless message of a .raw file that he sent, to then send the file.txt.

//  char buf[] = "Hello, World!";
//  bot.sendFile((byte*)buf, strlen(buf), FB_DOC, "test_raw.txt", CHAT_ID);

.....Connected
46
Those are the same!!

Let's do it slower
Instead of trying to send a file (even if it's working) we will just send a message

Ok then
But first try this code

Give me the outputs pls, and also if you receive the message or not!!

your credentials

#include "SPIFFS.h"
#include <FastBot.h>
//FastBot bot(BOT_TOKEN);

String readstring, BOT_TOKEN;

void setup() {
  Serial.begin(115200);
  while (!Serial)
    ;

  connectWiFi();

  if (!SPIFFS.begin()) {
    Serial.println("FS Error");
    return;
  }

  File file;

  file = SPIFFS.open("/BOTA.txt", "r");
  if (file) {
    while (file.available()) {
      readstring = file.readStringUntil('\n');
    }
    file.close();
  }

  BOT_TOKEN = tokenhere; //put your token here pls

  if (readstring == BOT_TOKEN)
  {
    Serial.println("Those are the same!!");
  }
  else
  {
    Serial.println("The token from the file isn't the same");
    int i;
    for(int i = 0 ; readstring[i] == BOT_TOKEN[i] ; i++)
    {
      Serial.print(BOT_TOKEN[i]);
    }
    if (i != readstring.length())
    {
      Serial.println("The first diff char is:");
      Serial.print(readstring[i]);
      Serial.print('\t');
      Serial.print(BOT_TOKEN[i]);
      Serial.println();
      Serial.print(readstring[i], HEX);
      Serial.print('\t');
      Serial.print(BOT_TOKEN[i], HEX);
    }
  }

  FastBot bot(BOT_TOKEN);

  bot.sendMessage("Hello you", CHAT_ID);
}

void connectWiFi() {
  delay(2000);
  Serial.println();

  WiFi.begin(WIFI_SSID, WIFI_PASS);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
    if (millis() > 15000) ESP.restart();
  }
  Serial.println("Connected");
}

void loop() {
}

.....Connected
Those are the same!!

Pls make an effort and don't make me ask you each time if you recieved the message or not... I told you to tell THE OUTPUTS AND IF YOU GET THE MESSAGE

See in post@89 just printed that. And YES, Hello you arrived on telegram

Can you give it a try pls:

your credentials

#include "SPIFFS.h"
#include <FastBot.h>
//FastBot bot(BOT_TOKEN);

String readstring, BOT_TOKEN;

void setup() {
  Serial.begin(115200);
  while (!Serial)
    ;

  connectWiFi();

  if (!SPIFFS.begin()) {
    Serial.println("FS Error");
    return;
  }

  File file;

  file = SPIFFS.open("/BOTA.txt", "r");
  if (file) {
    while (file.available()) {
      readstring = file.readStringUntil('\n');
    }
    file.close();
  }

  BOT_TOKEN = tokenhere; //put your token here pls

  if (readstring == BOT_TOKEN)
  {
    Serial.println("Those are the same!!");
  }
  else
  {
    Serial.println("The token from the file isn't the same");
    int i;
    for(int i = 0 ; readstring[i] == BOT_TOKEN[i] ; i++)
    {
      Serial.print(BOT_TOKEN[i]);
    }
    if (i != readstring.length())
    {
      Serial.println("The first diff char is:");
      Serial.print(readstring[i]);
      Serial.print('\t');
      Serial.print(BOT_TOKEN[i]);
      Serial.println();
      Serial.print(readstring[i], HEX);
      Serial.print('\t');
      Serial.print(BOT_TOKEN[i], HEX);
    }
  }

  FastBot bot(tokenhere);

  bot.sendMessage("Hello you", CHAT_ID);
}

void connectWiFi() {
  delay(2000);
  Serial.println();

  WiFi.begin(WIFI_SSID, WIFI_PASS);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
    if (millis() > 15000) ESP.restart();
  }
  Serial.println("Connected");
}

void loop() {
}

In this field I write the entire String between quotes ("dfdshgdsghds:fdfjkhffkhhkfhfdhfdh"). Like this ?

The message arrived and see the serial monitor:

My bad I made a mistake
In the line you quote, replace "tokenhere" by "readstring" pls (without the ")

I had done the test with the String value in quotes. Now I tested using a string. Consider the same result, I got the message and the serial monitor is the same as in post#94

So that's a good news because here you just init your bot with the value that was in the file .txt

Now, go on telegram and copy YOUR token from your bot

Replace my token in the .txt file by yours
Same thing in the BOT_TOKEN variable in the code
And try it again

(!!!! Do a copy paste pls! So we're sure those are the same token)

OK. Everything happened the same, I received Hello you and the serial monitor showed the same message as in post#94.

Now we need to go back and insert that original piece of code that was uploading a file.

I mean, read the String from the BOTA.txt file

You already did it bro
Here is the code simplified, you can see that there is no longer BOT_TOKEN but only readstring which contains the value coming from the BOTA.txt file

your credentials

#include "SPIFFS.h"
#include <FastBot.h>
//FastBot bot(BOT_TOKEN);

String readstring;

void setup() {
  Serial.begin(115200);
  while (!Serial);

  connectWiFi();

  if (!SPIFFS.begin()) {
    Serial.println("FS Error");
    return;
  }

  File file = SPIFFS.open("/BOTA.txt", "r");
  if (file) {
    while (file.available()) {
      readstring = file.readStringUntil('\n');
    }
    file.close();
  }

  Serial.println("The token from the file:");
  Serial.println(readstring);
  Serial.print("Its length:\t");
  Serial.println(readstring.length());


  FastBot bot(readstring);

  bot.sendMessage("Hello you", CHAT_ID);
}

void connectWiFi() {
  delay(2000);
  Serial.println();

  WiFi.begin(WIFI_SSID, WIFI_PASS);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
    if (millis() > 15000) ESP.restart();
  }
  Serial.println("Connected");
}

void loop() {
}

Give it a try!

Sorry, I meant this one, which sends file

file = SPIFFS.open("/BOT.txt", "r");
  bot.sendFile(file, FB_DOC, "test.txt", CHAT_ID);
  file.close();

So in your memory, what file do you have?
I mean there is BOTA.txt of course, and what are the others?
What is the name of the file you want to send?