Hangouts Chat: how to retrieve project_id or client_id in incoming event request? - hangouts-api

I have setup a fully operational chat bot in Hangouts Chat orchestrated by a tailored webserver. I would like now to be able to have this webserver to interact with other Hangouts bots that I created and to route some requests to some of my other servers that will have to know which bots initiated the event.
With other provider, such as Slack, the app_id is provided in the event request data.
But with hangouts, this is not the case. I could not find any data in the request body or headers that represent either project_id or client_id.
In a more simple way my question is : "How to identify the Hangouts bot that send me an event request?" :)

An event request's response will contain an Event instance in its body, which one of its fields will be an User object. That User object will contain a name field that will represent the user's id (whether it's a human or a bot).
It will look like this:
{
"name": "users/<id>",
"displayName": "<name that appears in the chat>",
"type": "BOT"
}

One month later, I finally found the time to answer my question :)
In order to identify the Hangouts project that is calling your server, when you receive an event from Hangouts Chat, you'll find in the incoming request the header Authorization whose value is something like Bearer abcd1234.
If you decode this JWToken (ie, abcd1234 in our example), in the resulting data, you'll have a field aud which is exactly the "project number" of your Hangouts app. This "project number" can be found at "https://console.cloud.google.com/home/dashboard?project=referenceofyourprojecthere".

Related

How to unassign a user from a Whatsapp Business Account using WhatsApp Meta API

I can assign system users to a specific WhatsApp Business Account by sending a POST request to this endpoint
https://graph.facebook.com/LATEST-VERSION/WHATSAPP-BUSINESS-ACCOUNT-ID/assigned_users
Link to documentation
But, apparently, there's no way to unassign them using a DELETE request
At the same time, documentation also says that DELETE calls to that endpoint count against rate limits
So, can I unassign a user from a WABA using any endpoint of any of the Meta APIs? Can't find it in the documentation.
Many thanks in advance

Using Instagram's Graph API, how can I retrieve post data (media url, caption, poster username, etc)

I want to use Instagram's Graph API on my backend server to retrieve data about an Instagram post. On my frontend, users will submit a post URL (like https://www.instagram.com/p/CAvPIm2lszQ/). Then on my backend, I want to take the ID of the post from that URL (so in this case CAvPIm2lszQ) and then I'm hoping that I can pass that ID thru the Instagram Graph API and then retrieve the data that I need (media URL, caption, poster username, etc.).
So would that be possible? I did find documentation on "IG Media" for the Graph API, but under permissions, it says, "A Facebook User access token from a User who created the IG Media object, with the following permissions.."
Unless I'm misunderstanding it, I'm not sure if I'll be able to access posts from various public accounts. I think it's also worth mentioning that my users are not logging into their Instagram accounts to use my service so the only possible "User access token" would be my own.
Any ideas on how I can go about this? I was using the instagram.com/p/{post_id}/?__a=1 endpoint to meet my needs before but it doesn't work on my production server for some reason. So I'm kinda stuck.
Most probably you will not be able to achieve that using Instagram API. First of all the ID you are referring to CAvPIm2lszQ is not the ID that you will use for getting IG Media. The ID is different (it's numeric value like in the sample request from the page you've linked). The full URL that includes CAvPIm2lszQ is in the shortcode field.
At the moment it is not possible to look for the post detail using shortcode. If you want to use that endpoint you need to get the real post ID first, for instance by listing list of posts from given user.
But in order to do so - you need to use Facebook login authorization window to get token from given user. Alternatively you can try to request https://developers.facebook.com/docs/instagram-api/guides/business-discovery but it requires going through App review and having your own company to pass the Business Verification. Keep in mind that this endpoint returns information only about Instagram Professional accounts (Business/Creator account). You will not be able to get information about regular accounts.
And the last thing about ?__a=1 endpoint. This is not the official Instagram API. They use it only for their own purposes. Most probably your server IP address has been blocked due to sending too many requests.

Go to chat message with specific text with Telegram API

I'm looking for information about this, but I don't find anything.
Is possible send to user to a chat message that contains a specific text?
This request below can be made with multiple languages.
https://api.telegram.org/bot[BOT_API_KEY]/sendMessage?chat_id=[MY_CHANNEL_NAME]&text=[MY_MESSAGE_TEXT]
where:
BOT_API_KEY is the API Key when you created your bot
MY_CHANNEL_NAME is the handle of your channel (e.g. #my_channel_name)
MY_MESSAGE_TEXT is the message you want to send (URL-encoded)
https://medium.com/#xabaras/sending-a-message-to-a-telegram-channel-the-easy-way-eb0a0b32968

Identify unique user in Dialogflow V1

So I am testing out Dialogflow and one of the first questions I have is: how does my bot know who it is talking to? I need to identify a user and keep that information for as long as I can. The basic scenario being:
User starts his/her first conversation.
Chatbot send a fulfillment request to the server trying to match a user within its own database.
The user is found, the information (as a JWT or some other token) is sent back to Dialogflow and stored there for further communication. In reality, this part would involve asking for user email, sending a verification code to that email and then verifying the user with the code.
User then starts chatting with a bot and all fulfillment requests get the unique token stored for this very user, so that my REST API knows which user is being served with the response.
Couldn't find anything about it in the docs (maybe I am looking in the wrong places).
There will be several integrations, like Messenger, Viber, Telegram. I dunno, maybe those APIs add some unique information on the user?...
Thanks for the help!
Sorry, I know it's been a while, but maybe this will help someone else.
The right solution here is a user id, not a session id. A user id is provided by the chat platform (Facebook, Slack etc) and is consistent across sessions for the same user.
To get the user id, go to the Fulfillment tab, enable the editor and use a function like so:
let r = request.body.originalDetectIntentRequest
//this makes sure that you're on an integration
if (r["source"]){
return r.payload.data.sender.id;
}
To tie together ids from different platforms, you probably have to have some kind of log-in process every time you encounter a new id on a platform.
Pop,
Sessions are built in already into DialogFlow requests to your fulfilment service, if you check the payload you will find a sessionId, it remains the same for the same client until it expires.
However if you want to identify the user from any of the clients that you can connect to DialogFlow like Messenger then from the same request payload to you you will notice that there is an object named originalRequest that is only available when requests are coming from those clients.
You can personalize those users response eg using their FB firstname in a message to them.

Sample of Instagram webhook notification data

I am currently doing an integration to the Instagram API and would like my app to receive webhook notifications whenever there is new media on any Instagram account which has authorized my app via OAuth.
I've been able to write the code which sets up my app to receive notifications using the instructions here. However, I noticed that the Instagram API docs contain no information on what the data in a change notification will look like. My searches online have also come back void. I need sample Instagram webhook notification data so I can write code to parse the data and apply it for my purposes.
I would have gone ahead to expose my localhost to the internet via ngrok, so Instagram would send data to my callback URL when I post a photo to my Instagram account. However, I discovered that the Instagram API does not allow you use an ngrok URL as a callback URL.
Now the only option I have is to deploy my partially completed code to an actual web server. Hoping someone else who has previously integrated to the API can share the format of the webhook notification data. I really don't want to have to do deploy my application at this point.
I eventually had to deploy my partially completed code to a web server. I put a logger behind my webhook callback URL to record the notification data sent to it by Instagram. Below is what it looks like:
[
{
"object": "user",
"object_id": "123456789",
"changed_aspect": "media",
"time": 1506338651,
"data": {
"media_id": "1611605324545559190_123456789"
},
"subscription_id": 0
}
]
The Instagram webhook notification payload/data is a JSON array of objects, each of which contains information on a single change to an Instagram account. Each JSON object contains the following fields:
object: A string whose value is always "user"
object_id: The ID of the Instagram account on which the subject change occurred
changed_aspect: A string whose value is always "media"
time: The Unix epoch indicating when the subject change occurred
subscription_id: The ID of the Instagram subscription object through which this notification was sent. A subscription object is created to ask Instagram to send webhook notifications to your app and is essentially a callback URL.
data: A JSON object containing the following fields:
media_id: The ID of the new Instagram media object (photo, video or carousel) whose creation triggered this webhook notification