Curl return TRUE if is there CURLOPT_RETURNTRANSFER, TRUE ? - php

Hi guys I'll explain my code:
I have a telegram bot and I have to write many messages quickly in a group and to write a message it is necessary to execute a link (using the Telegram Api).
To do this I use Curl:
curl_setopt($ch, CURLOPT_URL, $url_telegram);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, getRandomUserAgent());
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_TIMEOUT, 80);
$return= curl_exec($ch);
if($return !== FALSE){ //cURL works
save_variable_in_js_file();
}
If the message is written I believe it must be:
$return == TRUE or maybe != False
So if is not false is run a functionsave_variable_in_js_file()
that save a variable in a javascript file.
The strange thing is that some message are not written by bot, it seems not works and maybe its $return was == FALSE, but anyway the function is run and the variable saved in the file.
Why this ?
I know withCURLOPT_RETURNTRANSFER, TRUE
$return
's curl can berequest
orfalse
.
Is this the problem ?
The method used withAPI Telegram
to send message issendMessage
: https://core.telegram.org/method/messages.sendMessage
EDIT:
When i write a message with bot, and all is ok, it return thisJSON
:
ok: true
result:
message_id: 546
from:
id: xxx1
is_bot: true
first_name: "name bot"
username: "name bot"
chat:
id xxx111
title "name group"
username "name bot"
type "supergroup"
date 1627749641
text "Ciao"
maybe I could do this:
if(json_decode($return, true) ['ok']){
save_variable_in_js_file();
}
What do you think ?
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: illegal string offset
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.