Telegram `setTyping` API call - telegram

I'm trying to set my bot's typing status by sending the following POST request (based on the API docs):
https://api.telegram.org/bot{{botToken}}/setTyping
{
peer: {{chat_id}},
typing: true,
action: 'sendMessageTypingAction'
}
I've tried a few variations of it, such as changing the url to be /messages.setTyping and sending the action as {"_":"sendMessageTypingAction"} as seen here, but all I get is:
{
"ok": false,
"error_code": 404,
"description": "Not Found: method not found"
}
Anyone know what I'm doing wrong?

Thanks to #tashakori for pointing me in the right direction towards the Bot API. For posterity, what I needed to do was:
https://api.telegram.org/bot{{botToken}}/sendChatAction
{
chat_id: {{chatId}},
action: 'typing'
}

The link you have mentioned above belongs to Telegram Core APIs which is used for handling ordinary accounts of Telegram. These so-called Core APIs are not related to Telegram Bot APIs.
The only API that is somehow similar to SetTyping for bots is AnswerCallbackQuery, which can be used only when responding to the user's interaction with inline keyboards. (you can send a text to the user, saying that there is a process running in the background and whenever the user's answer is ready, you can send it using APIs like sendMessage)

Related

How do you respond to a thread in Google Chat from an incoming webhook?

There's a thread that my webhook has previously created that it wants to reply to. Is this possible using a webhook? It seems to be possible with a bot, see this answer:
https://stackoverflow.com/a/58657945/3832377
But I can't find any documentation on doing it from a webhook. As I've created the original message in the thread, I can guarentee a consistent threadId.
I tried to send a body that looked like:
{
"cards": [/* a card */]
"thread": { "name": "some_thread_name" }
}
But received a 500 error.
Documentation: https://developers.google.com/hangouts/chat/reference/rest/v1/spaces.messages/create
States you have to add the threadKey as a query parameter, not in the request body.

google cloud vision api quickstart error opening file

I am following the following Google Cloud Vision quickstart:
https://cloud.google.com/vision/docs/quickstart
This is using the API Explorer, and I get
Error Opening File
I have created a bucket named vision2018, and checked Share Publicly for the file.
My portion of the request related to the file is:
"image":
{
"source":
{
"imageUri":"gs://vision2018/demo-image.jpg"
}
}
The response I get is:
{
"responses": [
{
"error": {
"code": 5,
"message": "Error opening file: gs://vision2018/demo-image.jpg\"."
}
}
]
}
}
What do I need to specify in order to access files in my GCP storage?
Alternatively, I read other Stack Overflows that talk about GOOGLE_APPLICATION_CREDENTIALS, Simple API Key, and "Create Service account key and download the key in JSON format", ... but these seem to be giving commands in the shell, which this quickstart doesn't even open.
Is there initial setup assumed prior to the quickstart?
I am not ready to call the api from code
You might want to doublecheck your request. I went to the quickstart, replaced the placeholder imageUri with gs://vision2018/demo-image.jpg and it worked just fine. The error message you posted is what would be displayed if you had given gs://vision2018/demo-image.jpg\" instead.
Regarding the second part of your question: these are authentication methods. In this particular case, under Authentication you will find a drop down which lets you chose between API key and Google OAuth 2.0. If you chose the former, you don't need to do anything as a demo key will be used just for the purposes of the quickstart. If you chose OAuth 2.0, a popup will appear prompting you to authenticate with a google account. All in all, what you need to do is follow step-by-step the instructions given by the quickstart.
I was receiving a similar JSON response from the Google Vision API:
"error": {
"code": 7,
"message": "Error opening file: gs://bucket/file.jpg."
}
The fix was to set the GCS file's permission to public-read:
gsutil acl set public-read gs://bucket/file.jpg
Finally I investigated what happened. The problem is that your API token is only grant for process the image (allow right to use OCR engine), but that API is not also for accessing object in GS.
Therefore "message": "Error opening file:
The problem is similar with this post:Authorize Google Cloud Vision API to Google Storage image Maybe the error message is a bit dumb than many years ago.
The solution also mentioned in the answer section, but if you want some thing more clear (expose security side-effect) here it is: Set GCS read-only public
Reason I want to keep using API because it's better for use it in mobile application, we cannot give the OAuth2.0 to any phone. However, still find a way to secure the read-public bucket.

How to receive update if someone blocks Facebook Messenger Bot?

So I have created Messenger bot. Is there a way to receive webhook when someone who was interacting with bot has blocked it? Similar to how you can set up webhook when someone uninstalls facebook app.
When a user first interacts with the bot I store his information in the database. If he decides to block the bot, I want to delete that row from the database so receiving messenger_id would be completely enough.
I read through FB docs but did not find anything useful. Would appreciate if someone could help.
You will receive an error code when you try to message the user from your bot. Probably something similar to this:
{
"error": {
"message": "This Person Cannot Receive Messages: This person isn't receiving messages from you right now.",
"type": "OAuthException",
"code": 10,
"error_subcode": 2018108,
"fbtrace_id": "BLBz/WZt8dN"
}
}
Try going through your response logs finding that user PSID to see the exact error you are getting, but it should be very similar to the above.
So what you have to do is update the user when you get a response like this consistently, perhaps set a counter or build a rule for when you decide is enough to remove the user form your DB or disable. More info on the errors here:
https://developers.facebook.com/docs/messenger-platform/reference/send-api/error-codes

Telegram Inline Bot not call webhook

I've created new bot for Telegram. I've set /setinline in BotFather for my bot. I've added a webhook that is called when I send a message to bot but this webhook is not called if I write something in the bot chat without send any message.
Any idea how to solve?
Yes, it does, probably you're inspecting the wrong param, it will call the same webhook, first remember you set the webhook by doing:
https://api.telegram.org/bot<BOT_TOKEN>/setWebhook?url=<YOUR_URL>
and like you mentioned, you need to enable /setinline through BotFather, then it will call your endpoint with a message with the following body:
{
"query":"tex",
"from": {
"username":"user",
"first_name":"firstname",
"last_name":"lastname",
"id": 8888888,
"language_code":"en-US"},
"id":"7777777",
"offset":""
}
Remember it will call your endpoint on key-up you may receive a ton of request.

How to receive & process data when I subscribe to youtube api v3 push notification?

According to this https://developers.google.com/youtube/v3/guides/push_notifications
I can subscribe to a youtube channel & receive push notification for any new video.
My callback server is a php script which interprets POST/GET data:
<?php
if (isset($_GET['hub_challenge'])) {
print $_GET['hub_challenge'];
}
else {
$xml=file_get_contents("php://input");
file_put_contents('endpoint.txt',$xml);
}
?>
But $xml is empty. In the docs it says:
The YouTube Data API (v3) supports push notifications via
PubSubHubbub, a server-to-server publish/subscribe protocol for
Web-accessible resources. Notifications are pushed out to subscribers
via HTTP webhooks, which is much more efficient than polling-based
solutions.
But it does not specify how does it send the data....whether in POST body or in somewhere else.
So How do I get the atom feed in my script?
EDIT: I should probably ask a new question for this...but anyway....I tried this channel (https://www.youtube.com/channel/UCATp8LNTjzjNlLxdArp0Myg); but when I try to subscribe it says "restricted topic" (I did not provide token as it is a public channel). Same for any other channel ID. Is something wrong with my callback server? I also tried runscope url as a callback server for testing. But it did not help.
Others are having similar problems. Here is the issue log:
https://code.google.com/p/gdata-issues/issues/detail?id=7138
and related StackOverflow question:
Youtube API - Subscribing to Push Notifications
Unfortunately, no one seem to provide a solution although you can follow the issue and track any progress.
Yes it send data on the POST body . If you are using Express Nodejs add app.use(bodyParser.xml()) middleware to parse xml data

Resources