HipChat API Tokens v1 vs. v2 - hipchat

In v1 of the HipChat API, you could create a token (let's call it "Notifier") that would be able to notify any room on the server. Any messages sent using this token will appear from "Notifier" in HipChat.
In v2, you can create a personal access token with notification permissions that can post on your behalf, but they will show up under your name, not "Notifier." Alternatively, you can create a room-specific token with notification permissions, but you have to create a separate token for each room you want to notify.
Is there a way to mimic the above-described v1 behavior in v2?

No way to mimic the v1 behavior. The limitation on the v2 is by design. What are you trying to accomplish?

Related

How to use Google Oauth2.0 to authenticate user via Telegram Bot

This is my first time interacting with Google API and I'm using python3.9 with this library Python Telegram Bot
I want to access a user Google API Calendar via a telegram bot and I can't seem to find any article to guide me through it. My key problem (I think) is redirecting the success authorization flow back to telegram bot.
This is what I have in mind:
In the telegram app, user send '/send' to bot
Bot receive message and return a google an authorization link to user
User clink on authorization link and allow access
Bot receive authorization access and completes the Oauth flow
The problem lies betweeen step 3 and 4. A standard authorization link is
https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=<clientid>&redirect_uri=<redirect_uri>&scope=<scope>&state<state>&access_type=offline
How do I send the authorization link back to my telegram bot? Should I create another API endpoint to receive that authorization link? Or can I send telegram api send_message() in the <redirect_uri> to redirect the success message to my bot.
Update 1
Thanks to CallMeStag, I manage to figure out a way to complete the oauth process. For people who faced the same problem, this is what I did
Pre-requisite: Credentials is created in google console api - Web application. redirect_uri set as localhost:8000 (During development phase)
User send '/send' to bot
Bot receive message and return an authorization link https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=<clientid>&redirect_uri=http://localhost:8000/&scope=<scope>&state<state>&access_type=offline
User click on link to authenticate and it will redirect to http://localhost:8000. Used fastapi as a webhook to receive the message. Capture the authorization code, use google.oauthlib.flow to complete the authorization process. Next, redirect user back to telegram link https://t.me/<botname>
Start using user google calendar
It's currently indeed not very straight forward for a PTB-application to listen for external updates (the auth verification in this cas) - see also this issue. Currently it might be easiest for you to set up a custom webhook application that runs in parallel to the Updater - e.g. using flask/django/starlette/fastapi/…. Alternatively, if you're using webhooks for your bot anyway, you can patch the Updater to do the job for you. Although that requires some manual work - see here for an example.
Once you are able to listen to updates coming from Google, handling them can be done via PTBs usual handler setup, specifically via the TypeHandler or even a custom Handler subclass - see this FAQ entry.
Regarding the redirect url: You'll want to redirect your user back to your bot, so you'll have to provide a link that does that. Bot.link should probably do the trick.
Disclaimer: I'm currently the maintainer of python-telegram-bot.

DM to any user on Slack using Slack API

I'm trying to send Direct Messages (DMs) to a user on Slack using chat.postMessage using Bot token. But I'm only able to send messages to the users that are in my workspace.
How can I send message to any user on another workspaces?
When I try to do so, I get: "error": "channel_not_found"
I've that user's UserID (U02....), user's email and my Bot token.
When you create a bot/app in Slack, you grant it OAuth Scopes which provide the bot access to certain information in your Slack instance. So for example, I expect you have added the users:read Bot Token Scope to your Slack app, so that it can determine the users, and userId's in your workspace.
However, this scope restricts the bot to only see users in your workspace.
There's a couple of ways around this though:
Solution 1 - Slack Connect
Now in Slack, you can message users in other workspaces with a feature called Slack Connect.
You'll first need to establish a connection with the user you want the bot to message. This can be arranged via an invite process, and once completed that userId should become available to the bot. You can use that userId in the channel field of the chat.postMessage API to direct message the user from the other workspace.
Solution 2 - Org Level App
If you are on an Enterprise version of Slack, you should have multiple workspaces within a company, that are all linked by an enterpriseId.
In this case, a possible solution might be to create what is known as an Org Level App to have access to information across multiple workspaces. More information on Org Level apps can be found here.

Slack slash command: Respond as user, not app

When sending the response to a Slack slash command, I would like to send it under the user that has launched the slach command.
I have created a Slack app with a slash command. It calls my Flask webservice and I use the "response_url" webhook to write something back to the channel. The response in the channel is given by my app. This works as expected. But I would like for the response to be displayed as if a user has given it.
An example would be the Slack plugin from giphy. If I call it, I get an ephemeral message to choose the gif I would like. But then it is posted in the channel under my name.
So I have 2 questions:
How does the API call look like to respond to the slash command as a specific user?
What permissions for my app are required to allow for such behaviour of the app?
The Slack API documentation is comprehensive, but much research didn't yield the result I wanted.
Thanks!
When you are using response_url, you can't customize your username or icon. For this, you'll need to use chat.postMessage API method. There are now two ways to achieve what you need here:
Use user token: This gives you access to take actions on the behalf of the user. Although, you'll need to take authorization from every user you want post the message as.
Request chat:write.customize scope with your bot token: You can post a message with icon_url and username parameters where you can provide the user's icon and name respectively for both the parameters. This is much easier, as this only requires one-time authorization.
More information in the official documentation.

How to get the tenant name when integrating with Microsoft Teams

I have created a Microsoft Teams bot that can create/update conversations and receives all kinds of events to an endpoint (user joined team, ...). All I see in the events is a tenant id. For teams, i get an id and sometimes a name which is great.
to create/update conversations I use this flow:
Get a token from https://login.microsoftonline.com/botframework.com/oauth2/v2.0/token
POST to a channel: ${serviceUrl}v3/conversations/${conversationId}/activities
My question is, how can I get the name of a tenant? I can not find any API to do so?
Use case: A user sends me a support email. I have no way to check my database and find the correct entries because all I know is the tenant id.
I have looked into the Graph API but I'm not sure if my bot is actually able to make those calls (I get all kinds of strange permissions errors such as Authorization_IdentityNotFound The identity of the calling application could not be established.).
I want to make the calls to the API myself. I don't want to use any Microsoft SDK/Lib/...
It looks like I have to:
In Azure Portal -> App registrations -> API permissions add the Microsoft Graph application permission Organization.Read.All
For each tenant, ask the Microsoft Teams admin to visit: https://login.microsoftonline.com/${tenantId}/adminconsent
Get a graph token for the tenant via https://login.microsoftonline.com/${tenantId}/oauth2/v2.0/token (scope: graph.microsoft.com/.default)
Call the graph api https://graph.microsoft.com/v1.0/organization

Slack API: How to list your bot applications?

I want to list the bots owned by any user through the slack api. The list of applications owned by a user is missing from user.info and user.list. Which api method could I use to list the applications any one user owns? Or vice versa if I have a bot application id how could I determine who owns said bot?
The endpoint you are looking for is team.integrationLogs.
This method lists the integration activity logs for a team, including
when integrations are added, modified and removed. This method can
only be called by Admins.
You will have to parse through the log with all changes to get the current state, but this is the only endpoint with that kind of information.

Resources