slack api invite bot to a channel - slack-api

I need to call slack api to invite my bot to channel. I can do that in slack app, but when I do that via api, I always get user_not_found.
I call
https://slack.com/api/channels.invite?token=<legacy token>&channel=<channel>&user=<bot user name>
I use legacy token, not a bot token, valid channel and bot user name that obtained on bots config page.But I always get 'user_not_found'. How to invite bot to a channel?

For inviting a user to a channel you need to specify the user ID, not the user name in the API call to channels.invite. In your case the user ID of your bot user. You also need to specify the channel ID for the channel.
Example:
https://slack.com/api/channels.invite?token=TOKEN&channel=C12345678&user=U12345678
The bot user ID should be part of the token you received when installing the corresponding Slack app. Or you can call users.list to get it.

Related

Is it possible to get a webhook/event at the user level for the Slack API?

I would like to build an app where users add a configuration and I can retrieve their user token so the app can act on behalf of the user.
I would like to be able to receive webhook events (much like if a bot user were in a public or private channel) whenever the user receives a message, is this possible?
A while back you could achieve this with a personal user token and hooking into the event stream via sockets but this has been deprecated.
Did some snooping, they moved the User Tokens over to the same area as the Bot tokens. You DON'T have to do some weird configuration if the app is installed by you, you automatically get a new user token section.
You can then go to the Events section and subscribe to events on behalf of users.

Twilio: Send SMS from connected account

Here's what I'm trying:
curl -X POST -d "Body=Hi there, this is a test message from cURL" -d 'From=+1aaabbbcccc' -d "To=+1zzzxxxyyyy" "https://api.twilio.com/2010-04-01/Accounts/$TWILIO_CONNECTED_SUBACCOUNT_SID/Messages" -u "$TWILIO_CONNECTED_MAIN_ACCOUNT_SID:$TWILIO_AUTH_TOKEN"
Where $TWILIO_CONNECTED_SUBACCOUNT_SID is a account SID with the phone number I want to send from. $TWILIO_CONNECTED_MAIN_ACCOUNT_SID is the account SID that the connect button sent back to me (has a name like "Subaccount for ConnectApp: ..."). $TWILIO_AUTH_TOKEN is my (not the connected account's) auth token.
I've tried various permutations of the 3 account SIDs but can't get any of them to work. How do I send an SMS on behalf of a connected account?
I got it to work if I purchase a new number for the $TWILIO_CONNECTED_MAIN_ACCOUNT_SID account via cURL. But I don't want to build a UI for purchasing numbers in my app, I want to let users just pick a number they already own on Twilio, from their main account. Is that possible?
Twilio developer evangelist here.
According to the docs, under permissions:
Charge account for usage
This allows your Connect App to perform actions that charge your user’s Twilio account such as make and receive phone calls, send and receive SMS messages, and buy phone numbers. Your Connect App will not have access to resources in the user’s parent account, like phone numbers. Instead, your Connect App must buy phone numbers on behalf of the user, using the Account SID passed to your Authorize URL.
Emphasis mine.
So, you cannot use a connect account to send messages from existing resources. You will need to buy a new number to send.
An alternative to using Connect here, that would give you access to the account's resources would be to have the user submit their Account SID and an API Key/Secret pair. While it's never ideal to share credentials, an API Key/Secret pair can be easily deactivated without affecting the rest of the account.

Discord OAuth2 how to check if a bot is in (joined) a guild

I'm using Discord OAuth2 for my discord bot dashboard. I retrieve the user's servers by the link https://discord.com/api/users/#me/guilds. I want to prompt the user to add my bot to his guild or go directly to the dashboard if the bot is already in the user's guild. But how do I know if the bot is already in a guild? I didn't find any API that does this.
It's an API request per guild, but you could use get guild member with your own bot's ID; if you get a 4xx then your bot isn't present in the guild.

How to Get User Token for Slack API?

I made a new Slack App, got both my user token and bot token, and now my app can post messages as me. But what if I want this app to post messages as someone else from my team? How to get their token? Or where they can find it?
Tokens in slack can only be retrieved from the your slack apps OAuth page. This cannot be done via the API. If you want to send the messages as another user what you need to do is:
Create the a slack app using the users account.
Assign the relevant permissions to the app.
Install the app to your work space.
Fetch the generated tokens from the OAUTH and permissions section.

Is it possible to add other users to different slack channels using Slack API as admin?

The channel.join api in the slack web api does not have a slack userid field. The problem is since there are lot of channels in our slack team user gets confused on which channels to join. So we have segregated channels based on internal teams. And if an user selects his team he should be able to auto-join all the channels which are related to him.
As an admin of the slack team is it possible to add other users to different slack channels using Slack API?
You can use the Slack API method channel.invite to invite users to any slack public slack channel. It allows you to specify the channel and user by ID.
See here for the documentation.

Resources