Telegram API - sending local .png

Hi i trying to do following:

  1. Export chart image to my local disk

  2. Send this image via Telegram API with short message with emojis

My problem is i cant get/upload local file. I achieved by Python already from this videoguide

I know its possible with Amipy plugin but i like to achive just in AFL if its possible. I tryed in several ways but i can send successfuly just image uploaded on FTP not local.

i use as example formulas from @beppe and @rajandran and Pythonic way from videoguide above..i tryed InternetOpenURL() function also...

Version(6.17);  //Code is Compatible with 6.17 and Higher

TelegramAlerts = ParamTrigger("Telegram Alert","Send Alert"); // Button in Parameters window
TelegramAPI_ID = ParamStr("Telegram Bot API Key","1627937571:AAG0eXwVtD6_lzxgVrhKLPPqYjaATGDKm0g");  //Get the Bot API key via BotFather in Telgram
TelgramCHAT_ID = ParamStr("Telegram Channel ID","-1001319842264");  //Channel ID example : @marketcalls_in

if (TelegramAlerts) 
	exportPath = "C:\\Program Files\\AmiBroker\\ExportedImages\\"; // export path for chart image
	fmkdir( exportPath ); // Create the path if it does not exists
		AB = CreateObject("Broker.Application");
		AW = AB.ActiveWindow;
		AW.ExportImage( exportPath + Name()+" "+ Now(1)+".png"); //Export image with name XYZ dd/mm/yy.png
	My_exported_image = exportPath + Name()+" "+ Now(1)+".png";// Path to exported image
	my_test_image =fopen("C:\\Program Files\\AmiBroker\\ExportedImages\\AMD 15.02.2021.png","rb"); // full path for testing
	cat_image_test = "";//testing image (it works in param "photo=")
	emo = "u'\U000026C4'"; 
	emoji = "\u2731" ;
		ph = InternetPostRequest(""+TelegramAPI_ID+"/sendPhoto?chat_id="+TelgramCHAT_ID,"files="+my_test_image/*there must be inserted local file fh*/+"&caption=somethingelse new"+emoji);
		  printf("There is problem with POST Request !");

		printf("There is problem with FILE opening !");


The second one (but its not so serious :smile:) i trying send emoji in unicode but its going wrong...:frowning:

signal 1.PNG signal 2

Anybody knows please??

Please read the docs

fopen returns file HANDLE, not file contents. So you are sending some binary handle via POST request which is pretty much useless as remote server can't use file handles to your local files.
To send a photo you would need to read the content of the file and convert to acceptable format of post request (properly encode to string because InternetPostRequest requires STRING, not binary data). From Telegram docs you can read that

they require binary data to be sent as multipart/form-data
InternetPostRequest function sends data in Content-Type: application/x-www-form-urlencoded

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.