GyverLibs / FastBot

Многофункциональная быстрая библиотека для Телеграм бота на esp8266/esp32
MIT License
186 stars 32 forks source link

some messages are not sent #20

Closed frak0d closed 2 years ago

frak0d commented 2 years ago

Hello, I am having a problem with your library. Some particular messages are not being sent. they do get printed to console, but aren't sent. What am I doing wrong ?

here is my code :-

#define LED_BUILTIN 2
#define WIFI_SSID "ssid"
#define WIFI_PASS "pass"
#define BOT_TOKEN "here"

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

void connectWiFi()
{
  delay(2000);
  Serial.begin(115200);
  Serial.print("WiFi");

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

#define SEND_MESSAGE(MSG) bot.sendMessage(MSG, msg.chatID)

void on_msg(FB_msg& msg)
{
  ;;;; if (msg.text == "/start")
  {
    SEND_MESSAGE("Hello! My Name is Khosla v0.1\n"
                 "I run on an ESP32 Microcontroller!"); // doesn't work
  }
  else if (msg.text.startsWith("good bot"))
  {
    SEND_MESSAGE("***good human***");
  }
  else if (msg.text.startsWith("/say"))
  {
    if (msg.text.length() > 5)
      SEND_MESSAGE(msg.text.c_str()+5);
    else
      SEND_MESSAGE("can't say nothing **ya dumb dumb!**"); // doesn't work
  }
}

void setup()
{
  connectWiFi();
  bot.attach(on_msg);
  bot.setPeriod(1000);
  bot.setTextMode(FB_MARKDOWN);
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop()
{
  digitalWrite(LED_BUILTIN, HIGH);
  delay(10);
  digitalWrite(LED_BUILTIN, LOW);
  bot.tick();
}

here is a screenshot of chat :-

image

here is serial console output :-

WiFi.....Connected
Hello%21+My+Name+is+Khosla+v0\.1%0aI+run+on+an+ESP32+Microcontroller%21
***good+human***
can't+say+nothing+**ya+dumb+dumb%21**
hi+there

some extra information :-

GyverLibs commented 2 years ago

Hi. Try to disable markdown mode. It can conflict with some of your symbols

GyverLibs commented 2 years ago

From documentation

Attention! In FB_MARKDOWN mode, characters cannot be used in messages are ! + #, the message will not be sent.

frak0d commented 2 years ago

ok thanks.

Another problem I have is that the bot is not working in groups, even though i have turned off privacy mode.

GyverLibs commented 2 years ago

this is strange. Try echoBot example

frak0d commented 2 years ago

this is strange. Try echoBot example

that doesn't work in groups either.

GyverLibs commented 2 years ago

try to create new bot. I just tried: library v2.25, new bot, echoBot example, in group - works like a charm

frak0d commented 2 years ago

thanks for advice, but it didn't work.

it works fine in other groups, just not in one particular group. It seems something is wrong with my group permissions.

I fixed it by promoting the bot to admin.

GyverLibs commented 2 years ago

Yep! There are groups and supergroups. Seems to be in supergroup bot must be an admin