Slack Conversations API conversations.info "channel_not_found" - slack

I have a Slack bot that uses a slash command, but I first need information from the conversation.
Required Scopes for conversations.info (mine only needs im:read and mpim:read):
channels:read groups:read im:read mpim:read
payload = request.form
headers = request.headers
trigger_id = payload['trigger_id']
channel_id = payload['channel_id']
user_id = payload['user_id']
timestamp = headers['X-Slack-Request-Timestamp']
conversation_info = slack_client.conversations_info(
token=SLACK_BOT_TOKEN,
channel=channel_id
)
This code is returning the "channel_not_found" error when I invoke the Slack Bot from within my personal DM's, am I missing something? I have both im:read and mpim:read scopes added. I even tried the tester from Slack's API page and it doesn't work either.

I have been ashed this on Slack Support, and they said, you can not see information about private channels and direct messages, which the bot is not member of. They said, privacy is over everything.
You can invite a bot into private groups with /invite #BotName, but you can't invite to direct messages.
You can only see information about direct conversation, if you are using a UserToken, and the token's owner is part of that DM.

Related

Post proactive messages in Slack conversations with Bolt for Java

I'm trying to start a proactive conversation with a user using the Slack Bolt SDK for Java but I don't know how to get a client for the Bot token, this is my code so far:
Bot bot = ...; // with botToken, botUserId, botId and so...
ConversationsOpenResponse conversation = app.client().conversationsOpen(conv -> conv
.users(List.of(user.getSlackUserId()))
);
But every request I try to make returns with error=invalid_auth because it's laking the auth token (bot token in this particular case).
Every example I found relies on a context with a client tied to the installer bot.

How to get the name of the slack channel from conversation menu?

I have added a slack conversation dropdown and in the response I want to save/show channel name (or conversation name). I'm able to get the public channels information through conversation.info API but for the private channels, I am not able to fetch any details. Can someone help me how I can get the names along with channel id (or conversation id).
This is the response from the slack on selecting a channel
{'values': {'channel_block': {'selected_action_id': {'type': 'conversations_select', 'selected_conversation': 'G0*****JM'}}}}
The token you're using to call conversations.info must have access to the channel in question before you can access it. I'm assuming it doesn't, but without seeing the response from the API I can't be sure.

How to let a user join channel in Slack App

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).

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.

How to send message to another user via bot and come back to original conversation with first user without losing the context?

I am trying to build a bot that can address the requests placed by the user. However, the bot needs to ask permission of the user's manager for the same. So this is the flow:
User places a request to the bot.
Bot informs user's manager to either approve or reject the request
Based on the response from manager, bot either address the request or does not and informs the user.
I am able to make a 1:1 conversation between bot and user using the PromptDialog, and perform steps 1 and 3. However, I am not sure how to send message to another user for approval or rejection and continue the earlier conversation with the first user. I am using C# for this bot. Any ideas on how could I do this?
Thanks
Niyati
After sending the message to a second user using the following code and storing in the inbox of the first user, you can send the stored result, again using the above code, to the first user and follow their conversations.
string recipientId ="123456789"; // For Example
string serviceUrl = "https://telegram.botframework.com"; // For Example
var connector = new ConnectorClient(new Uri(serviceUrl));
IMessageActivity newMessage = Activity.CreateMessageActivity();
newMessage.Type = ActivityTypes.Message;
newMessage.From = new ChannelAccount("<BotId>", "<BotName>");
newMessage.Conversation = new ConversationAccount(false, recipientId);
newMessage.Recipient = new ChannelAccount(recipientId);
newMessage.Text = "<MessageText>";
await connector.Conversations.SendToConversationAsync((Activity)newMessage);
The code comes from here.
check this page, specifically the start conversation section.
You could keep a context stack for each user, pushing an item on top of the stack for each message sent by the bot and matching context in FIFO order for each message recieved. Now this context stack goes into a map identified by the userId/userKey.
Bot-context is a library which does exactly this. The related blog post.

Resources