I'm unable to successfully upload a file even using Slacks file.upload tester mechanism here: https://api.slack.com/methods/files.upload
I've applied a Slack app token, channel name, and chosen a file, but get the following result:
{
"ok": false,
"error": "missing_scope",
"needed": "files:write:user",
"provided": "identify,incoming-webhook"
}
I then created a new app, and ensured that files: write was in scope (it wasn't in the previous app). Now, I get a different error:
{
"ok": false,
"error": "not_in_channel"
}
As a test to confirm that the channel name was ok, I subsequently tried a nonexistent channel name, and the error indicated 'channel_not_found', so the channel name I used should be valid.
I had the same issue and fixed it by adding the Slack app to the channel
I guess there are many ways to add it;
I just opened the corresponding channel I was trying to "files.upload" to, and clicked the "Add an app" link at the really top of the channel history:
Before posting a message, reacting to any message or uploading files you need to open a conversation with the channel. You can also do it programmatically and achieve this with the help of API (https://api.slack.com/methods/conversations.open)
You just need to invite the app that you created into the slack channel. Example:
#AppBot
Related
I'm trying to mute notifications particular group in Slack workspace. Is there any API method available to do?
I've tried using the web-API method mentioned in this GitHub page https://github.com/ErikKalkoken/slackApiDoc/blob/master/users.prefs.set.md.
It causes no error in response but the channels I provided in the 'muted_channels' parameter wasn't muted.
In my case, I didn't have to send a prefs payload as ErikKalkoken described, but instead this one. Found it out thanks to this Tweet: https://twitter.com/slackhq/status/457711460425027584
{
"name": "plain_text_mode",
"value": True
}
I am trying to create a slack command that takes params, generate image and return and image back to user, also the image upload should display as the bot user.
I follow this post: Can you upload a file to the Slack API using files.upload as a different user?
I tried creating slack app, a bot user according to it, and slack file upload api as follows:
def send_picture(channel_id, graph_details):
sender_token = "xoxb-..." # bot-user token
pic = {
'file' : ('img.png', open('img.png', 'rb'), 'png')
}
payload={
"title" : "Serverless App Report",
"channels" : [channel_id]
}
r = requests.post("https://slack.com/api/files.upload", params=payload, files=pic)
Whenever the user do the slack command(POST with params), I can parse the channel_id to find out the sender and pass it into the channel_id into the file upload api.
Posting it into public channel is working fine. But posting it back to the user who do the command failed with the error: {"ok":false,"error":"invalid_channel","channel":"DXXXXXXX"}
The reason you get this error is that your bot user is apparently not a member of the private channel in which the user invoked your slash command. Therefore your app can not upload any files to it. This normal behavior and part of Slack's security architecture.
There are 3 workarounds for this issue:
You can make sure the bot user from your Slack app is added as member to all private channels where your slash command needs to work
You can request every user to "install" your Slack app once. Thereby providing your app with a user specific Slack token which your app can then use to access the private channel.
You can refrain from uploading files and instead reply with a message, which can include images too. A Slack app can always reply to a Slash command, no matter in which kind of channel it is issued.
I'm working on a new Workspace app for Slack. I have a use case where I need to send notifications to users in Slack, through a direct message (or IM). Since the chat.postMessage endpoint requires a channel ID, I can get the existing IM channels using conversations.list and send them the notification.
However, if the user hasn't yet opened an IM channel from their side, I need to create one. It seems that neither Web API endpoints (conversations.open or im.open) support Workspace tokens. I keep getting not_allowed_token_type error response. I can create a public channel with conversations.create, but that's not what I need.
Is there another to open an IM channel to a user when using a Workspace token?
Took me awhile to figure this out. You need to add/request the conversations.app_home:create scope to your permissions. Then you can just specify the user ID as the channel arg in a chat.postMessage call.
So I'm building a slack app in Node that responds to some user commands. It usually responds with an interactive message that has some attachments and buttons.
For certain buttons, I return different types of texts or other attachments, but I also want to have a "Cancel" button that would basically cancel the current command - delete it from the user's chat.
The thing is that I want to do it without having to request the chat:write:user scope or without having to create a bot.
By asking for the chat:write:user scope I can basically remove any message the user created, but it asks for that scope when installing the app and gives my app permission to post on behalf of the user, which most find uncomfortable.
By creating a bot I could achieve this, but again it asks for permission to add a bot to the channel and I don't want this.
What I've tried
Use chat.delete method, but I get { ok: false, error: 'missing_scope', needed: 'chat:write:user', provided: 'identify,commands' } from Slack, even when I try with as_user set to false.
Respond with an empty message to the command, like res.send(), or res.send({ text: null }), or res.send({ attachments: null }), etc.
When you reply to a user command on Slack it overrides by default the previous content. I just want to override with nothing, basically removing the original response. When I try this however, it doesn't do anything, unless I provide some content.
I'm pretty sure #2 is the way to go and I feel I'm close and it's something pretty simple but out of my sight.
Working example of what I want
I know it can be done because the GIF Keyboard app for slack does this. When searching for Gifs, they have a "cancel" button at the bottom that just removes the current command/message. Furthermore, they only ask for the Commands scope.
You are on the right track. Option #2 works, so no need to request scopes to delete a message.
Just send the following response back to Slack and the last (ephemeral) message from your app will be deleted:
{
"response_type": "ephemeral",
"replace_original": true,
"delete_original": true,
"text": ""
}
I'd like to check that my bot credentials (appId + appSecret) are ok to connect to https://api.botframework.com/bot/v1.0/messages.
I can't send a real message because i have no conversation running so I tried to post the following json message :
{ "type": "Ping"} but the response i got was
{
"error": {
"message": "Expression evaluation failed. Object reference not set to an instance of an object.",
"code": "ServiceError"
}
}
Is there any way to check if my access to the api is ok?
If you've registered your bot, you can visit the Bot Framework page, click on the My Bots menu, and select your registered bot. On your bot page, scroll down to the bottom left and there's a test box.
Also, you can use the emulator. It has a place in the upper right corner to replace the default credentials with your bot credentials. Then change the URL to where you have your bot deployed. Tip: remember to append 'api/messages' to the URL.
Download the BotFrameworkEmulator to test connectivity to your bot. It works on windows and OSX if you have mono installed. You can change the default settings that the emulator uses by typing '/settings' after running it. You will be prompted to enter your appId, appSecret and url endpoint for sending and receiving messages to/from your bot.
You can also use the directline rest api to initiate conversations and send messages to your bot