Telegram bot api : issue with GIF upload/download size - telegram

Faced with issue, when i am trying to send GIF to my bot, but bot can't access to original size of image. Seems like telegram servers converting it to mp4 (it is a good idea, looks fine) and when i trying to download it - it always looks like a thumbnail with maximum 320px of bigger side.
Looks, like it is an api bug, because for example here :
It describes as 600x473px, but real downloaded mp4 size is :
So, trying to understand - where i'm wrong here, as original gif size require for my project needs... Maybe any workaround exists here?
ps. in case of converting gif to mp4 manually with saving quality and size and then submitting to bot - it works awesome, without any additional compression and etc, but it is unacceptable to ask use do it before using bot.
update :
To reproduce (you need you bot/bot_token and also, be able to receive webhook with json) :
1) sending this gif (https://c2n.me/47Y3H37.gif) to the bot via windows 10 telegram client (v2.1.10). Using "send without compression".
Gif size : 600x473, 3.35MB
2) Bot received and Telegram sending webhook :
{
"update_id": 290360893,
"message": {
"message_id": 21,
"from": {
"id": 101483786,
"is_bot": false,
"first_name": "edited",
"last_name": "edited",
"username": "edited",
"language_code": "en"
},
"chat": {
"id": edited,
"first_name": "edited",
"last_name": "edited",
"username": "edited",
"type": "private"
},
"date": 1591962500,
"animation": {
"file_name": "9Ywn9p.gif.mp4",
"mime_type": "video/mp4",
"duration": 4,
"width": 600,
"height": 473,
"thumb": {
"file_id": "AAMCAgADGQEAAxVe42t2MTQQrFMyXbskwWiNkHjm3wACKwgAAtZ-GEtFrAh9bgzTOnpJm5QuAAMBAAdtAAMIgQACGgQ",
"file_unique_id": "AQADekmblC4AAwiBAAI",
"file_size": 15304,
"width": 320,
"height": 252
},
"file_id": "CgACAgIAAxkBAAMVXuNrdjE0EKxTMl27JMFojZB45t8AAisIAALWfhhLRawIfW4M0zoaBA",
"file_unique_id": "AgADKwgAAtZ-GEs",
"file_size": 68253
},
"document": {
"file_name": "9Ywn9p.gif.mp4",
"mime_type": "video/mp4",
"thumb": {
"file_id": "AAMCAgADGQEAAxVe42t2MTQQrFMyXbskwWiNkHjm3wACKwgAAtZ-GEtFrAh9bgzTOnpJm5QuAAMBAAdtAAMIgQACGgQ",
"file_unique_id": "AQADekmblC4AAwiBAAI",
"file_size": 15304,
"width": 320,
"height": 252
},
"file_id": "CgACAgIAAxkBAAMVXuNrdjE0EKxTMl27JMFojZB45t8AAisIAALWfhhLRawIfW4M0zoaBA",
"file_unique_id": "AgADKwgAAtZ-GEs",
"file_size": 68253
}
}
}
, so you can see there, that size is correct, but weight - no, it is only 68253 bytes = 66.65kb, instead of ~3.35MB (some less, because of converting)
3) Get File_id : CgACAgIAAxkBAAMVXuNrdjE0EKxTMl27JMFojZB45t8AAisIAALWfhhLRawIfW4M0zoaBA from this webhook and trying to use it in api by calling GET "https://api.telegram.org/bot{your_bot_token}/getFile?file_id=CgACAgIAAxkBAAMVXuNrdjE0EKxTMl27JMFojZB45t8AAisIAALWfhhLRawIfW4M0zoaBA" and you will receive :
{
"ok": true,
"result": {
"file_id": "CgACAgIAAxkBAAMVXuNrdjE0EKxTMl27JMFojZB45t8AAisIAALWfhhLRawIfW4M0zoaBA",
"file_unique_id": "AgADKwgAAtZ-GEs",
"file_size": 68253,
"file_path": "animations/file_12.mp4"
}
}
4) Downloading file using this file_path :
GET "https://api.telegram.org/file/bot{your_bot_token}/animations/file_12.mp4" and... getting this mp4 file : https://c2n.me/47Y4oAv.mp4 , with loss quality, weight and size (320x252)
But when you are trying to download it from Telegram client - by clicking "save as" - works fine, mp4 with appropriate size/weight. So seems like an api bug...
update#2 : tried to submit it via tfs telegram support, but also, can't login using my phone number... (https://c2n.me/47Yqswl.png). #pavel_durov, could you please fix it all :))

It seems like the only workaround atm is to convert gif to mp4 (yeah, such a frustrating experience) until the issue is fixed.

Related

Deeplinking into a telegram bot

I have a simple use case. When a user clicks the link below,
T.me/MycompanynameBot?start=Microsoft
I want to show him 3 inline buttons corresponding to 3 Telegram channels within Microsoft. Is this possible?
The key is the bot must be able to retrieve the parameters from the URL.
Thank you.
Yes it's possible to retrieve bot parameter via answerCallbackQuery
Alternatively, the user can be redirected to the specified Game URL. For this option to work, you must first create a game for your bot via #Botfather and accept the terms. Otherwise, you may use links like:
t.me/your_bot?start=XXXX
that open your bot with a parameter.
Here is an example I made for you :
{
"ok": true,
"result": [{
"update_id": 89590932,
"message": {
"message_id": 5978,
"from": {
"id": 223110107,
"is_bot": false,
"first_name": "Ğąme",
"last_name": "Ǿver!",
"username": "GameO7er",
"language_code": "en"
},
"chat": {
"id": 223110107,
"first_name": "Ğąme",
"last_name": "Ǿver!",
"username": "GameO7er",
"type": "private"
},
"date": 1579094448,
"text": "/start Microsoft",
"entities": [{
"offset": 0,
"length": 6,
"type": "bot_command"
}]
}
}]
}
As you can see type=bot_command so you can parse the message if (type == "bot_command") and get text and substring /start from the original text or what ever you want to do.
In many cases I detect users with the parameters for example when I wanna to know who invited this user to bot I share the link in this format:
t.me/NameBot?start=ReferUserID
for example :
t.me/NameBot?start=223110107
is my ID and I can see how many user I've invited to the bot.
Hope be useful.

How can I retrieve a RingCentral call recording from a monitored incoming call?

I'm monitoring incoming calls on RingCentral by listening for the Call Session Notifications (CSN) telephony/sessions event filter:
/restapi/v1.0/account/~/extension/~/telephony/sessions
From this, I will receive events like the following. The recordings property will appear to indicate a recording is available. How can I retrieve this recording?
{
"uuid":"12345678901234567890",
"event":"/restapi/v1.0/account/11111111/extension/22222222/telephony/sessions",
"timestamp":"2019-03-08T22:30:40.059Z",
"subscriptionId":"11112222-3333-4444-5555-666677778888",
"ownerId":"33333333",
"body":{
"sequence":7,
"sessionId":"1234567890",
"telephonySessionId":"1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
"serverId":"10.11.12.13.TAM",
"eventTime":"2019-03-08T22:30:39.938Z",
"parties":[
{
"accountId":"11111111",
"extensionId":"22222222",
"id":"cs12345678901234567890-2",
"direction":"Inbound",
"to":{
"phoneNumber":"+16505550100",
"name":"Jane Doe",
"extensionId":"22222222"
},
"from":{
"phoneNumber":"+14155550100",
"name":"John Smith"
},
"recordings":[
{
"id":"44444444",
"active":false
}
],
"status":{
"code":"Answered",
"rcc":false
},
"missedCall":false,
"standAlone":false,
"muted":false
}
],
"origin":{
"type":"Call"
}
}
}
There are two ways to retrieve the recording using information in the Call Session Notification (CSN) event, specifically the recordings[0].id property and the sessionID property.
retrieving a full media URL by calling the call-log endpoint with the sessionId property
manually creating recording media URL using the recordings[0].id property.
Note 1: While the call is ongoing, the recording will not be available for retrieval, even when the recording id is present in the Call Session Notification event. The recording will be available to be retrieved shortly after the call concludes.
Note 2: Call recordings can be in MP3 or WAV format determined by the company. To distinguish check the response Content-Type header for the MIME type when retrieving the recording media file.
1) Retrieving Full Medial URL via Call Log API
Making an intermediate API call to the call-log API has the dual benefits of being the official approach for receiving a media URL an providing more metadata for the call. In this approach, the recording.id in the call-log record will match the recordings[0].id property in the Call Session Notification event.
Both the company account and user extension call-log APIs can be called with the sessionId parameter from the event as shown:
GET /restapi/v1.0/account/~/call-log?sessionId={sessionId}
GET /restapi/v1.0/account/~/extension/~/call-log?sessionId={sessionId}
In this example, the sessionId is 1234567890 so you would have a Company Call Log API URL as follows
GET /restapi/v1.0/account/~/call-log?sessionId=1234567890
The response object will have a recording property that provides hypermedia links to get the media file. The file can be WAV or MP3 format which is communicated in the response Content-Type header.
{
"uri": "https://platform.ringcentral.com/restapi/v1.0/account/11111111/extension/22222222/call-log?view=Simple&sessionId=1234567890&page=1&perPage=100",
"records": [
{
"uri": "https://platform.ringcentral.com/restapi/v1.0/account/11111111/extension/22222222/call-log/1234567890ABCDEFGabcdefgh?view=Simple",
"id": "1234567890ABCDEFGabcdefgh",
"sessionId": "1234567890",
"startTime": "2019-03-08T22:30:29.505Z",
"duration": 35,
"type": "Voice",
"direction": "Inbound",
"action": "Phone Call",
"result": "Accepted",
"to": {
"phoneNumber": "+16505550100",
"name": "Jane Doe"
},
"from": {
"phoneNumber": "+14155550100",
"name": "John Smith",
"location": "San Francisco, CA"
},
"recording": {
"uri": "https://platform.ringcentral.com/restapi/v1.0/account/11111111/recording/44444444",
"id": "44444444",
"type": "OnDemand",
"contentUri": "https://media.ringcentral.com/restapi/v1.0/account/111111111/recording/44444444/content"
},
"extension": {
"uri": "https://platform.ringcentral.com/restapi/v1.0/account/111111111/extension/22222222",
"id": 22222222
},
"reason": "Accepted",
"reasonDescription": "The call connected to and was accepted by this number."
}
],
"paging": {
"page": 1,
"perPage": 100,
"pageStart": 0,
"pageEnd": 0
},
"navigation": {
"firstPage": {
"uri": "https://platform.ringcentral.com/restapi/v1.0/account/11111111/extension/22222222/call-log?view=Simple&sessionId=1234567890&page=1&perPage=100"
},
"lastPage": {
"uri": "https://platform.ringcentral.com/restapi/v1.0/account/11111111/extension/22222222/call-log?view=Simple&sessionId=1234567890&page=1&perPage=100"
}
}
}
2) Manually Creating Media URL
You can call the Recording API endpoint and retrieve the media directly by manually constructing the recording URL as follows:
https://media.ringcentral.com/restapi/v1.0/account/{accountId}/recording/{recordingId}/content
In this example, the accountId is 11111111 and the recordingId is 44444444 for the following:
https://media.ringcentral.com/restapi/v1.0/account/11111111/recording/44444444/content
The accountId in the URL path can be set to the currently authorized user's account using ~. Alternately, it can be set explicitly by extracting the accountId from the event property or using the accountId property in the relevant party object. Using ~ is the recommended way to set accountId.
Note: This this approach can be quick, it may be error prone as RingCentral has changed the media hostname once in the past. While there are no anticipated, future changes, calling the call-log API and retrieving the full media URL from the response is the safer and recommended approach. See below for this approach. This is only included as some people will try this and potentially run into issues later.
3) Hybrid Approach
The first approach of calling the call-log end point is the recommended approach, however, it involves an extra API call and most of the time the second approach should work fine.
A hybrid approach is to construct the URL as in approach 2 and then fall back to approach 1 if approach 2 returns a 404 or other error.

Does the RingCentral Call Log API Return a "Missed" Value?

In the RingCentral Online Account Portal (https://service.ringcentral.com) and endpoint apps, the call log display shows whether a call was Inbound, Outbound or Missed.
In looking at the API Reference for the Call Log API, it seems that it only sends back Inbound or Outbound for "Direction". Does the developer Call Log API return a "Missed" value? Is there another way to get this information via the Call Log API?
Ref: https://developer.ringcentral.com/api-docs/latest/index.html#!#RefCallLog.html
This question appears to be in reference to the Online Account Portal UI's "Type" column as shown in this screenshot:
The web UI's "Type" column shows Inbound, Outbound or Missed. This can be generated by using the response properties for both direction and result.
direction API response property will be Inbound or Outbound
result API response property is an enumerated value that includes Missed and other values including Voicemail which is the example screenshot. A full list is available in the link below:
Ref: https://developer.ringcentral.com/api-docs/latest/index.html#!#ResultStatusValues
Here is an example response:
{
"uri": "https://platform.ringcentral.com/restapi/v1.0/account/11111111/call-log?view=Simple&showBlocked=true&withRecording=false&dateFrom=2018-08-27T06:18:00.000Z&page=1&perPage=100",
"records": [
{
"uri": "https://platform.ringcentral.com/restapi/v1.0/account/11111111/call-log/22222222?view=Simple",
"id": "22222222",
"sessionId": "33333333",
"startTime": "2018-08-27T17:38:12.634Z",
"duration": 27,
"type": "Voice",
"direction": "Inbound",
"action": "Phone Call",
"result": "Missed",
"to": {
"phoneNumber": "+16505550101"
},
"from": {
"phoneNumber": "+16505550102",
"name": "LOS ALTOS CA",
"location": "Los Altos, CA"
}
}
],
...
}
Please read this blog to find out more information you can find from the call log.

Cloud Vision API - PDF OCR

I just tested the Google Cloud Vision API to read the text, if exist, in a image.
Until now I installed the Maven Server and the Redis Server. I just follow the instructions in this page.
https://github.com/GoogleCloudPlatform/cloud-vision/tree/master/java/text
Until now I was able to tested with .jpg files, is it possible to do it with tiff files or pdf??
I am using the following command:
java -cp target/text-1.0-SNAPSHOT-jar-with-dependencies.jar com.google.cloud.vision.samples.text.TextApp ../../data/text/
Inside the text directory, I have the files in jpg format.
Then to read the converted file, I don't know how to do that, just I run the following command
java -cp target/text-1.0-SNAPSHOT-jar-with-dependencies.jar com.google.cloud.vision.samples.text.TextApp
And I get the message to enter a word or phrase to search in the converted files. Is there a way to see the whole document transformed?
Thanks!
On April 6, 2018, support for PDF and TIFF files in document text detection was added to Google Cloud Vision API (see Release Notes).
According to the documentation:
The Vision API can detect and transcribe text from PDF and TIFF
files stored in Google Cloud Storage.
Document text detection from PDF and TIFF must be requested using the
asyncBatchAnnotate function, which performs an asynchronous request and provides its status using the operations resources.
Output from a PDF/TIFF request is written to a JSON file created in the specified Google Cloud Storage bucket.
Example:
1) Upload a file to your Google Cloud Storage
2) Make a POST request to perform PDF/TIFF document text detection
Request:
POST https://vision.googleapis.com/v1p2beta1/files:asyncBatchAnnotate
Authorization: Bearer <your access token>
{
"requests":[
{
"inputConfig": {
"gcsSource": {
"uri": "gs://<your bucket name>/input.pdf"
},
"mimeType": "application/pdf"
},
"features": [
{
"type": "DOCUMENT_TEXT_DETECTION"
}
],
"outputConfig": {
"gcsDestination": {
"uri": "gs://<your bucket name>/output/"
},
"batchSize": 1
}
}
]
}
Response:
{
"name": "operations/9b1f9d773d216406"
}
3) Make a GET request to check if document text detection is done
Request:
GET https://vision.googleapis.com/v1/operations/9b1f9d773d216406
Authorization: Bearer <your access token>
Response:
{
"name": "operations/9b1f9d773d216406",
"metadata": {
"#type": "type.googleapis.com/google.cloud.vision.v1p2beta1.OperationMetadata",
"state": "RUNNING",
"updateTime": "2018-06-17T20:18:09.117787733Z"
},
"done": true,
"response": {
"#type": "type.googleapis.com/google.cloud.vision.v1p2beta1.AsyncBatchAnnotateFilesResponse",
"responses": [
{
"outputConfig": {
"gcsDestination": {
"uri": "gs://<your bucket name>/output/"
},
"batchSize": 1
}
}
]
}
}
4) Check the results in the specified Google Cloud Storage folder
In 2016 PDF and TIFF formats was not supported for Cloud Vision.
The accepted formats are : (taken from the the doc)
JPEG
PNG8
PNG24
GIF
Animated GIF (first frame only)
BMP
WEBP
RAW
ICO
But now are added.
Docs for jpg:
https://cloud.google.com/vision/docs/ocr
Docs for pdf
https://cloud.google.com/vision/docs/pdf
https://cloud.google.com/vision/docs/pdf
I know this question is old, but now Google Vision released support for PDF!
Now google cloud vision text detection is available in for pdf file as well which detect text in pdf file immediately in synchronous way and doesn't require file to be in google storage it can be in base 64 format.
HTTP method and URL:
POST https://vision.googleapis.com/v1/files:annotate
Request JSON body:
{
"requests": [
{
"inputConfig": {
"content": "base64-encoded-file",
"mimeType": "application/pdf"
},
"features": [
{
"type": "DOCUMENT_TEXT_DETECTION"
}
],
"pages": [
1,2,3,4,5
]
}
]
}
For more information on it visit https://cloud.google.com/vision/docs/file-small-batch

Rule score not visible for each rule in Google Pagespeed

I was going through google pagespeed and thought of giving a try. I went through a couple of tutorials to learn about the same.
In the tutorials they showed that each rule had an associated score parameter. However, the response that I got has only a ruleImpact parameter for each rule and no score parameter.
This is what I used :
https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url=https://www.google.com&key=XXXXXXXXXXXXXXXXXXXXX
And this is the response I got (not showing the entire response but only the first few lines)-
{
"kind": "pagespeedonline#result",
"id": "https://www.google.com/",
"responseCode": 200,
"title": "Google",
"score": 99,
"pageStats": {
"numberResources": 11,
"numberHosts": 4,
"totalRequestBytes": "2159",
"numberStaticResources": 9,
"htmlResponseBytes": "114193",
"imageResponseBytes": "46012",
"javascriptResponseBytes": "857355",
"otherResponseBytes": "210",
"numberJsResources": 5
},
"formattedResults": {
"locale": "en_US",
"ruleResults": {
"AvoidLandingPageRedirects": {
"localizedRuleName": "Avoid landing page redirects",
"ruleImpact": 0.0,
"urlBlocks": [
{
"header": {
"format": "Your page has no redirects. Learn more about avoiding landing page redirects.",
"args": [
{
"type": "HYPERLINK",
"value": "https://developers.google.com/speed/docs/insights/AvoidRedirects"
}
]
}
}
]
},
"EnableGzipCompression": {
"localizedRuleName": "Enable compression",
"ruleImpact": 0.0,
"urlBlocks": [
{
"header": {
"format": "You have compression enabled. Learn more about enabling compression.",
"args": [
{
"type": "HYPERLINK",
"value": "https://developers.google.com/speed/docs/insights/EnableCompression"
}
]
}
}
]
},
Am I doing something wrong?
Rule impact is the "score" so to speak for the specific rules.
The impact (unbounded floating point value) that implementing the suggestions for this rule would have on making the page faster. Impact is comparable between rules to determine which rule's suggestions would have a higher or lower impact on making a page faster. For instance, if enabling compression would save 1MB, while optimizing images would save 500kB, the enable compression rule would have 2x the impact of the image optimization rule, all other things being equal.
This means that based on the recommendations being made, the ruleImpact of each are relative to each other in terms of how much of an impact that rule violation has on the score.

Resources