The first time I write telegram bot. He has some commands. Assume:

/ command1, / command2, text, if the command entered is not listed

A handler was made for them (interaction using webhuk).

Command1 is working properly.

And on command2, the handler must select a randomized line from a text file and return it. I do with this code:

$a = file('./file.txt'); $preload_text = $a[array_rand($a)]; sendMessage($chat_id, $preload_text); 

But in telegram does not return anything when you enter the command2.

Made a new test.php file in the same directory as the handler and shoved code into it:

 $a = file('./file.txt'); echo $a[array_rand($a)]; 

I open site.ru/test.php in the browser - everything works correctly.

If in $preload_text just set a string, then it returns correctly to the telegrams

What is the problem?

  • and $ preload_text is exactly a string, not an array of strings? - Anatol
  • @Anatol yes, for sure - Russian Bear
  • Have you tried to debug? - Anatol
  • Mistakes you catch? - Anatol
  • @Anatol I still have little idea how to debug a bot. Because I do not catch - Russian Bear

1 answer 1

 $preload_text = $a[array_rand($a)]; 

the string is returned, as it should => the problem is in the file, perhaps too much text?