You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
libTelegram is working fine for me on windows. Sends messages ok. I was uploading files as well by sending the URL and letting the telegram server pull the file from my server. However now I want to directly upload the image file. It seems the library does not support this yet. Can you give me some pointers on how to implement. I am experienced C++ programmer. Thanks
for example I have tried with no luck
telegram::sender sender(MyToken);
telegram::types::file f;
// slurp the file into file_id??
std::ifstream t("image.png");
f.file_id = "";
t.seekg(0, std::ios::end);
f.file_id.reserve(t.tellg());
t.seekg(0, std::ios::beg);
f.file_id.assign((std::istreambuf_iterator(t)),std::istreambuf_iterator());
sender.send_photo(123456789,f,"this is your image");
The text was updated successfully, but these errors were encountered:
You would need to upload the file manually, using multipart form data, as per https://core.telegram.org/bots/api#inputfile, and then reference that in your send_photo call. I haven't yet built this functionality into the library, so you'd need to make an API call to telegram yourself outside of libtelegram, using something like https://github.com/yhirose/cpp-httplib#multipartform-data-post-data. The httplib library is included at present as the default way of making poll requests, so you don't need to include anything else to implement this.
I'll update this issue when I get round to adding the upload logic.
libTelegram is working fine for me on windows. Sends messages ok. I was uploading files as well by sending the URL and letting the telegram server pull the file from my server. However now I want to directly upload the image file. It seems the library does not support this yet. Can you give me some pointers on how to implement. I am experienced C++ programmer. Thanks
for example I have tried with no luck
telegram::sender sender(MyToken);
telegram::types::file f;
// slurp the file into file_id??
std::ifstream t("image.png");
f.file_id = "";
t.seekg(0, std::ios::end);
f.file_id.reserve(t.tellg());
t.seekg(0, std::ios::beg);
f.file_id.assign((std::istreambuf_iterator(t)),std::istreambuf_iterator());
sender.send_photo(123456789,f,"this is your image");
The text was updated successfully, but these errors were encountered: