Simple Telegram Bot to extract text from image based on ocr api
Check out The Sample Bot
Go to @botfather and create a new bot. Copy your api token and setwebhook by pasting this link on browser.
· Change XXXXXX with your bot token
· Change url to domain you host the php file.
https://api.telegram.org/botXXXXXX/setWebHook?url=yourdomain.com/bot.php
Just edit 2nd line by changing api key on bot.php api key can be found here https://ocr.space/ocrapi
//Change OCR-KEY to your api key from ocr.space website
$result = file_get_contents('http://api.ocr.space/parse/imageurl?apikey=<OCR-KEY-XXX>&url='.$id_url);
$result=json_decode($result, true);
$str='';
foreach($result['ParsedResults'] as $pareValue)
{
$str.= strval($pareValue['ParsedText']);
}
if($str!=""){
$re=
array(
'chat_id' => $chatId,
'text' => "🔍Scanned Text:\n$str\n\n@horansoftware",
'disable_web_page_preview' => false,);
send("sendMessage", $re);
} #end
Don't forget pasting your bot token every where needed in the bot.php
$path = "https://api.telegram.org/bot<Your Bot Token>/";
Code Written by Gemechis Elias