How to let a user join channel in Slack App - slack

I am working on a slack app which has its bot also.A user can share a file from the bot to any public channel even if he is not in that channel. If user is not in the channel then firstly I will add the user in the channel and then share the file. For this slack provides api https://api.slack.com/methods/channels.join which helps a user join a channel. But it expects a user token corresponding to the user who wants to join the channel. Now the issue is I only have bot token(xoxb-) and api token(xoxp-) corresponding to the user which has installed the app. So how can I get the token corresponding to any user whom I want to join OR I am missing something here. Please help.

No, you do not need a token corresponding with the joining user.
When installing a Slack app with a bot user you receive two tokens: a bot token and an app token. The app token (but not the bot token) will work for inviting users to public channels, provided your app has the required scopes (channels:write).

Related

How to perform Teams Channel Authentication for bot framework?

I am working on team's bot that is scoped to teams' channel and group chat. I am using a external service that is being used by the bot. Now if I add the bot to channel or group chat, i want a way to only authorize certain group of users or use their auth token to access the external service within bot. In a personal chat as given by the example 46. (link: https://github.com/microsoft/BotBuilder-Samples/tree/main/samples/python/46.teams-auth) Teams auth in Bot framework samples, we can do auth when we click sign in and the user gets to login then pass the token to the bot. How to perform the same action (bit less intrusive) in a channel or a group chat?

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.

Microsoft Graph/Teams-is there a way to list a user's channels using delegated permissions?

I'm trying to convert some bot logic to use delegated permissions instead of application ones, but I'm running into an issue with a bot feature that can post to a Teams channel from a 1:1 conversation. The user can ask the bot to post to a channel, and this works fine, but when I take away Group.ReadWrite.All, I can't find a workaround that doesn't require admin consent. Here's the current flow:
Get the user's joined teams (me/joinedTeams-gets the user's joined Teams. This requires Team.ReadBasic.All.
Get the channels in the team (/teams/{id}/channels). This requires Group.Read.All (admin consent)
Post to the channel (/teams/{id}/channels/{id}/messages) which requires ChannelMessage.Send
So with delegated, non-admin permissions, I can list a user's teams, post a message to a channel on their behalf, but not list the channels on their joined teams? The docs here say that you need delegated Group.Read.All or ReadWrite.All, both of which require admin consent.
Is there another way that I'm missing to get a list of teams/channels for a user to cross-post to? I don't want to have to add the bot to the channel. I suppose I could create/store a list of connectors for each channel, but that's a lot of extra user overhead. The challenge is that I want to deploy this bot to an org that refuses to give any application/admin consent permissions to 3p apps.
I have no idea how I missed this, but there's a Channel.ReadBasic.All permission that doesn't require admin consent. This means I can do something like this in my bot:
Get a user's joined teams with graphClient.Users[aadUserId].JoinedTeams.Request().GetAsync()
Get the team's channels with graphClient.Teams[teamID].Channels.Request().GetAsync()
Post to the channel as outlined in the docs with c.Teams[teamID].Channels[channelID].Messages.Request().AddAsync(chatMessage).GetAwaiter().GetResult();
The only difference here is that the message is attributed to the user and not the bot, but as long as that's OK, this is a way to have a user initiated cross-post from a bot to a Team.

Getting Slack user email address for AWS Lex bot

I am creating a bot in aws-lex and will integrate it with Slack, FB Workplace and Yammer to start with.
I need to read the Slack user email address, then validate that against our webservice to ensure the user is registered. This will return some data about the users organisation that I need for further execution in lex.
I have no idea how to pass/extract the Slack user email (the one that is engaging in conversation with my Bot).
Any ideas?? Examples please! New to bot dev.
At least for slack you could do:
Under requestAttributes (from event) you can check the presence of x-amz-lex:channel-type. The value will be Slack if the user comes from slack.
You can then extract the user slack id from the event that is submitted to your lambda under the key userId
With that id, go to Slack API and call the method users.info. Now you can get the user email from the response.

Can user resume a conversation in a different channel? (Bot Framework)

Let's think of the following example:
1) I have a certain bot deployed on Azure
2) Bot can be talked via Facebook Messenger and via Skype
3) A certain user talks to the bot via Facebook Messenger and then he leaves.
4)A couple of minutes ago the same user resumes the conversation with the bot, but via Skype.
Is this possible? I assume Bot Framework doesn't have anything included for this, hence, that this isn't posible (as conversations are independent and state changes depending on the channel). Is there any way to identify a user (via some authentication method maybe), and then making this logic again?
Do any of you know any workaround for this?
Thanks in advance!
The Bot Framework Connector service is a component which provides a single API for your bot to communicate across multiple client services such as Skype, Email, Slack. Every bot and user has an account within each channel.
The channel account contains an identifier (id) and other informative bot non-structural data, like an optional name.
And there us unique conversation ID created for each conversation of each user for each channel. And you can customize your channel capabilities as described here.
Regards,
Jyo

Resources