Open edbrik opened 7 years ago
i think you must follow bellow code
int task = kernel.getKernelComm().getUploader().requestTask("C:\\virtual\\vivian.jpg", null);
kernel.getKernelComm().getUploader().waitForTask(task);
int resultState = kernel.getKernelComm().getUploader().getTaskState(task);
Uploader.UploadResult result = kernel.getKernelComm().getUploader().getUploadResult(task);
TLAbsInputFile inputFile;
if (result.isUsedBigFile()) {
inputFile = new TLInputFileBig();
inputFile.setId(result.getFileId());
inputFile.setName("vivian.jpg");
inputFile.setParts(result.getPartsCount());
} else {
inputFile = new TLInputFile();
inputFile.setId(result.getFileId());
inputFile.setName("vivian.jpg");
inputFile.setParts(result.getPartsCount());
}
TLAbsInputMedia _media = new TLInputMediaUploadedPhoto(); // for only send image png , jpg not as document
((TLInputMediaUploadedPhoto)_media).setCaption("caption");
((TLInputMediaUploadedPhoto)_media).setFile(inputFile);
TLAbsInputPeer _peer= (TLAbsInputPeer) new TLInputPeerUser();
((TLInputPeerUser)_peer).setUserId(id); //get user id from your db
((TLInputPeerUser)_peer).setAccessHash(hash); //get user hash from your db
TLRequestMessagesSendMedia request = new TLRequestMessagesSendMedia();
request.setPeer(_peer);
request.setMedia(_media);
request.setRandomId(rnd.nextLong());
TLUpdates tlUpdates = (TLUpdates) kernel.getKernelComm().getApi().doRpcCall((TLMethod) request);
hi.
thank you very much, one question more.
for send xlsx (MS Excel) and pdf files i try use the TLInputMediaUploadedDocument
but doest work.
TLAbsInputMedia _media = new TLInputMediaUploadedDocument ();
((TLInputMediaUploadedDocument )_media).setCaption("caption");
((TLInputMediaUploadedDocument )_media).setFile(inputFile);
for pdf file must change as follow
TLAbsInputMedia _media = new TLInputMediaUploadedDocument();
TLVector<TLAbsDocumentAttribute> attributes = new TLVector<>();
TLDocumentAttributeFilename fileNam = new TLDocumentAttributeFilename();
fileNam.setFileName("yourfile.pdf");
attributes.add(fileNam);
((TLInputMediaUploadedDocument) _media).setCaption("caption");
((TLInputMediaUploadedDocument) _media).setMimeType("application/pdf");//this based file extension
((TLInputMediaUploadedDocument) _media).setFile(inputFile);
((TLInputMediaUploadedDocument) _media).setAttributes(attributes);
Extension MIME Type
.doc application/msword
.dot application/msword
.docx application/vnd.openxmlformats-officedocument.wordprocessingml.document
.dotx application/vnd.openxmlformats-officedocument.wordprocessingml.template
.docm application/vnd.ms-word.document.macroEnabled.12
.dotm application/vnd.ms-word.template.macroEnabled.12
.xls application/vnd.ms-excel
.xlt application/vnd.ms-excel
.xla application/vnd.ms-excel
.xlsx application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
.xltx application/vnd.openxmlformats-officedocument.spreadsheetml.template
.xlsm application/vnd.ms-excel.sheet.macroEnabled.12
.xltm application/vnd.ms-excel.template.macroEnabled.12
.xlam application/vnd.ms-excel.addin.macroEnabled.12
.xlsb application/vnd.ms-excel.sheet.binary.macroEnabled.12
.ppt application/vnd.ms-powerpoint
.pot application/vnd.ms-powerpoint
.pps application/vnd.ms-powerpoint
.ppa application/vnd.ms-powerpoint
.pptx application/vnd.openxmlformats-officedocument.presentationml.presentation
.potx application/vnd.openxmlformats-officedocument.presentationml.template
.ppsx application/vnd.openxmlformats-officedocument.presentationml.slideshow
.ppam application/vnd.ms-powerpoint.addin.macroEnabled.12
.pptm application/vnd.ms-powerpoint.presentation.macroEnabled.12
.potm application/vnd.ms-powerpoint.template.macroEnabled.12
.ppsm application/vnd.ms-powerpoint.slideshow.macroEnabled.12
Hi .
The first time I uploaded an image worked fine but when I try again it does not send anything.
i change the code for
request.setRandomId(rnd.nextLong());
to
request.setRandomId(Math.round(Math.random()));
no problem i think this better maybe negative value create problem!
Math.abs(new Random().nextLong())
``
Works great, thank you very much for the support!!
hi amin1softco one question please.
How to know if the file was sent successfully?
hi edbrik i think with 1-try catch block and 2-stored result in tlUpdates and check read stat with updates recived
if problem occur you may get RPCException and better @rubenlagus say answer really i not member of telegram support 😄
Thanks for your support :D
Hi Amin and edbrik, could you please help me in finding a way to read old messages from a channel or supergroup. for example think that the user want to move and see old messages. how could I have access to old messages?
hi mehdi1602 with argument of TLRequestMessagesGetHistory you can handle this i think .
thanks Amin, I used as below
TLRequestMessagesGetHistory tlReq = new TLRequestMessagesGetHistory();
TLAbsInputPeer _peer = (TLAbsInputPeer) new TLInputPeerChat();
((TLInputPeerChat) _peer).setChatId(update.getChannelId());
tlReq.setPeer(_peer);
TLAbsMessages messagesEx = kernelComm.getApi().doRpcCall(tlReq);`
but all the time i get exceptions INVALID_CHANNEL_ID or INVALID_CHAT_ID
` org.telegram.api.engine.RpcException: CHAT_ID_INVALID`
could you please help me to know why I get this error?
hi amin, could you please let me know how can i download (photo , videos, and all files in general) that is related to a message? in other word how can i work with telegram downloader?
Hi.
I really tired create te object
TLAbsInputMedia
but i cant send messages with files or images This is the code I use