Java Telegram Bot: how to send photos having their file_id? - java

A few years ago I created a bot with telegrambots version 3.6.1.
Unfortunately there was a problem: every time that a user with user_ID>2147483647 joined the group, the bot crashed, as described here.
I've just found out how to update the version of telegrambots, but now I've another problem.
I need to use the setPhoto(String file_id) method as described here in Telegram ot JAVA API page (Pass a file_id as String to send a photo that exists on the Telegram servers).
It looks like that method doesn't accept String parameter anymore since telegrambots version 5.0.0.
Infact it worked until telegrambots version 4.9.2.
So my bot pins a message in the group with a list of many places, each one can have up till 2 photos.
Each of these photos has its file_id saved in a field of a MySql database.
So basically when we use the command to see a pic associated to a place, my code uses setPhoto(file_id) getting the file_id string from the database.
Now it looks like setPhoto(String) doesn't work anymore, so how can I solve this problem? I still need to use all the photo we saved in those years. How can i convert these file_id into InputFile argument?
I've tried to use version 4.9.2 of telegrambots and setPhoto(String) works, but I don't know if in that version, my original problem (numeric value out of range) was already solved and anyway I would like to use the latest version (6.4.0).
I've no idea how to convert String (fileID from database) to InputFile.
Thanks you very much.

The documentation is not really documenting anything, but it looks like the FileInput constructor can take String called attach(ement).

Related

element.sendKeys(password) method in Selenium sending too many keys

I'm writing Selenium tests for an application my company's working on. It's Selenium 3, and I'm using the 32-bit Internet Explorer Driver(IEDriverServer.exe) because I was using the 64-bit version but it was very slow to do anything.
I'm trying to populate a password field (with id="password"), and I'm using the following line of code:
driver.findElement(By.id("password")).sendKeys("welcome123");
where driver is an InternetExplorerDriver. What's happening instead of inputting the 10 characters "welcome123", is this:
The image of the populated password field
Please let me know what I can do to stop this from happening. I don't know what keys are being sent, but I am sure that in my code it says just "welcome123" and not something obvious like "welcome123_________".
Thanks!
Using the lines
driver.findElement(By.id("password")).click(); and
driver.findElement(By.id("password")).clear(); and then following it up with the
sendKeys("welcome123");
method call, the field is populated correctly. The problem was because IE was auto populating the password field based on password saving settings, and it was just tacking "welcome123" on the to the end.

How to create a testlink platform when using br.eti.kinoshita.testlinkjavaapi

I am trying to create an entire project on Testlink using the br.eti.kinoshita.testlinkjavaapi library.
The only thing I didn't manage to do is to create a new Platform.
I tried:
`api=new TestLinkAPI(new URL("http://"localhost/testlink/lib/api/xmlrpc/v1/xmlrpc.php),devKey);
//where devKey was taken from my testlink environment
Platform platform=new Platform(1,platformName,platformDescription);
api.addPlatformToTestPlan(projectId, testPlanId, platformName);
//projectId and testPlanId are directly taken from testlink and are both integer
//platformDescription is a String which looks like "a simple description"
// the "1" corresponds to the ID I want to give to my platform (I put 1 because none ID is already present on my project)
`
But this code is not efficient, and I get the error:
platformName does not exists.
I think the problem is that I have to first add the platform to the project but I can't find any method to do that...
Do you have any idea?

Programatically embed a video in a slideshow using Apache Open Office API

I want to create a plugin that adds a video on the current slide in an open instance of Open Office Impress by specifying the location of the video automatically. I have successfully added shapes to the slide. But I cannot find a way to embed a video.
Using the .uno:InsertAVMedia I can take user input to choose a file and it works. How do I want to specify the location of the file programmatically?
CONCLUSION:
This is not supported by the API. Images and audio can be inserted without user intervention but videos cannot be done this way. Hope this feature is released in subsequent versions.
You requested information about an extension, even though the code you are using is quite different, using a file stream reader and POI.
If you really do want to develop an extension, then start with one of the Java samples. An example that uses Impress is https://wiki.openoffice.org/wiki/File:SDraw.zip.
Inserting videos into an Impress presentation can be difficult. First be sure you can get it to work manually. The most obvious way to do that seems to be Insert -> Media -> Audio or Video. However many people use links to files instead of actually embedding the file. See also https://ask.libreoffice.org/en/question/1898/how-to-embed-video-into-impress-presentation/.
If embedding is working for your needs and you want to automate the embedding by using an extension (which seems to be what your question is asking), then there is a dispatcher method called InsertAVMedia that does this.
I do not know offhand what the parameters are for the call. See https://forum.openoffice.org/en/forum/viewtopic.php?f=20&t=61127 for how to look up parameters for dispatcher calls.
EDIT
Here is some Basic code that inserts a video.
sub insert_video
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dispatcher.executeDispatch(document, ".uno:InsertAVMedia", "", 0, Array())
end sub
From looking at InsertAVMedia in sfx.sdi, it seems that this call does not take any parameters.
EDIT 2
Sorry but InsertVideo and InsertImage do not take parameters either. From svx.sdi it looks like the following calls take parameters of some sort: InsertGalleryPic, InsertGraphic, InsertObject, InsertPlugin, AVMediaToolBox.
However according to https://wiki.openoffice.org/wiki/Documentation/OOoAuthors_User_Manual/Getting_Started/Sometimes_the_macro_recorder_fails, it is not possible to specify a file for InsertObject. That documentation also mentions that you never know what will work until you try it.
InsertGraphic takes a FileName parameter, so I would think that should work.
It is possible to add an XPlayer on the current slide. It looks like this will allow you to play a video, and you can specify the file's URL automatically.
Here is an example using createPlayer: https://forum.openoffice.org/en/forum/viewtopic.php?f=20&t=57699.
EDIT:
This Basic code works on my system. To play the video, simply call the routine.
sub play_video
If Video_flag = 0 Then
video =converttoURL( _
"C:\Users\JimStandard\Downloads\H264_test1_Talkinghead_avi_480x360.avi")
Video_flag = 1
'for windows:
oManager = CreateUnoService("com.sun.star.media.Manager_DirectX")
' for Linux
' oManager = CreateUnoService("com.sun.star.media.Manager_GStreamer")
oPlayer = oManager.createPlayer( video )
' oPlayer.CreatePlayerwindow(array()) ' crashes?
'oPlayer.setRate(1.1)
oPlayer.setPlaybackLoop(False)
oPlayer.setMediaTime(0.0)
oPlayer.setVolumeDB(GetSoundVolume())
oPlayer.start() ' Lecture
Player_flag = 1
Else
oPlayer.start() ' Lecture
Player_flag = 1
End If
End Sub

How to retrieve from Azure mobile services using android studio

I am new to Android and Windows Azure. I have successfully inserted data from Android application but how do I retrieve single data and post that data on a TextView?
The read function after the gettable class is also not working. What is the exact function use for it? I have followed these instructions but they did not work for me, also I do not understand the documentation.
Currently, I just can provide some tutorials about how to use query data from azure database. I recommend you can refer to this official document about how to use Azure Client Library using Java: https://azure.microsoft.com/en-us/documentation/articles/mobile-services-android-how-to-use-client-library . You can focus on two part: “how to query data from a mobile service” and “how to bind data to the UI”.
At the same time, you can view this video from Channel 9: https://channel9.msdn.com/Series/Windows-Azure-Mobile-Services/Android-Getting-Started-With-Data-Connecting-your-app-to-Windows-Azure-Mobile-Services.
The sample code project of this tutorial, please go to the GitHub link https://github.com/Azure/mobile-services-samples/tree/master/GettingStartedWithData .
For the ‘getTable(Class )’ function is not working, please double check whether the class name is same as table name. If they are same, you can use it like below:
MobileServiceTable<ToDoItem> mToDoTable = mClient.getTable(ToDoItem.class);
If not, you can write you code like this:
MobileServiceTable<ToDoItem> mToDoTable = mClient.getTable("ToDoItemBackup", ToDoItem.class);
For further better support, please share more detail about your code snippet .

OBJECT_NOT_FOUND when trying to getServingUrl of an image stored in GCS

I have written a Servlet where I am reading an image from blobstore, another image from GCS and then after applying a composite on both these images I am storing the composite image back in GCS.
My code works well till here.
After that, when I am trying to get the serving url for the composite image, I am getting an OBJECT_NOT_FOUND.
Just to experiment I manually uploaded a image in GCS and gave all the necessary permissions. Added the serviceaccount as OWNER and gave READ access to All users. And then again I am just trying to get the serving url. Following is my code:-
BlobKey newImageKey = blobstoreService.createGsBlobKey(gcsPath);
//log.severe("GCS PATH: " + gcsPath + " BlobKey: " + newImageKey);
ServingUrlOptions options = ServingUrlOptions.Builder.withBlobKey(newImageKey);
String profilePicLink = imgService.getServingUrl(options);
I also tried the below code:-
ServingUrlOptions options = ServingUrlOptions.Builder.withGoogleStorageFileName(gcsPath);
String profilePicLink = imgService.getServingUrl(options);
And in both the cases this is the error that I am getting:
/controller javax.servlet.ServletException:
java.lang.IllegalArgumentException: OBJECT_NOT_FOUND:
Btw, I have not enable billing as I am using the default bucket with the free quota. This is still in development so the free quota works for me.
OK, so I found out where exactly the exception is happening...
byte[] responseBytes = ApiProxy.makeSyncCall(PACKAGE, "GetUrlBase",
request.build().toByteArray());
and the exception it is throwing is :
ApiProxy.ApplicationException Application Error 8
Enabled billing and tried, still of no use :(
Have been trying to solve this the whole day and tried to search a solution everywhere.
Though this actually does not answer my original question but I have found a workaround. I installed python and gsutil and set the default acl of my bucket to read. Now when I am saving an image file in GCS I am just showing the public url link.
The above can also be achieved if in the GCSFileOptions we add .acl("public-read").
Once the acl is applied by either of the above two methods, in the GCS cloud console you can see the images shared publicly link check box comes as a dash and it says you do not have permission to edit permissions. I was getting confused seeing it, as I was expecting the checkbox to be checked.
But even in the above scenario the publicly shared link will work which is:-
http://storage.googleapis.com/[bucket_name]/[gcs_object_name]
I would still appreciate if someone can explain why the getServingUrl is not not working. Yes, it is still not working after set default acl to read.
Thanks,
Sukalpo.
I could not reproduce this issue by either uploading to Google Cloud storage via the console or via the App Engine GCS Java client. In both cases I could create a public URL for the image
even without specifying any specific permissions.
Do you want to create a production issue request,
https://code.google.com/p/googleappengine/issues/entry?template=Production%20issue
, so we can get more details about your specific case?
What is your gcsPath? I have to use:
"/gs/" + gcsFileName.getBucketName() + "/" + gcsFileName.getObjectName();
Honestly, the only way I've run into this error (and run into this unsolved question) was when I was accidentally using the wrong filename in a difficult to notice way while fetching the BlobKey using Google's APIs.
So, check the obvious things first.

Categories

Resources