I'm creating a web integration for my platform, using a bot user to "log" certain events.
I would like to have a new channel/group for each event type so they get shown in a list instead of all together in one channel. For this purpose I created a bot using the python Slacker integration.
Since the slack API refuses to let me create a channel as a bot user, I would need to use to the oauth2 API to create a channel and then let the bot write stuff in it. This means I need to authenticate as a user to slack with my platform.
This feels kind of hacky since the user I'd be using (probably my own) would be in the code just to create channels for the bot.
Is there a better way to do this? Whats best practice here?
Thanks!
Yes, there is a better way.
If you use a Slack app for your app you will receive two new access tokens during installation. A bot access token and a general access token. Both will have the scopes you specified during installation, but the later will not be limited to the bot subset. Use the later to create the new channels.
You will need to go though to oauth process to install your app for your Slack team, but only once for installation. The tokens will remain valid and should of course be stored by your app.
Not sure how a familiar you are with Slack apps, but you do not need to publish your app to the Slack App directory. That is optional.
See the official page about the Add-to-Slack button, section Add to Slack Flow.
Related
My setup is as follows: I have Dialogflow bot added as an app. The bot interacts with Slack and Dialogflow. The script uses dialogflow_fulfillment to handles the requests to return the response back to Dialogflow. At the same time, I want the bot to interact with the users like questionaries or buttons without routing back to Dialogflow. I can get it to post messages to any specified channel using client.chat_postMessage(). However I want to the bot to reply directly to the user when the user DM the app. I am not sure how this can be achieved. Please advise.
It turns out that using one app to monitor another app is not allowed by Slack. So this was not possible. The only possible way is to merge it to one app and use event api on it.
I have many features that can be customized within the bot and using the commands itself, but this can get confusing and may be bugged at times.
Would there be a way to allow users log into the website using Discord's API and to customize the bot from there?
It's similar to how MEE6 or carl and these bots allow users to customize or
buy a premium version, but just can't seem to find how I can do this myself.
An example is, a user can head onto the website and can turn on the moderation module through their account they have signed in with. This would then connect with the bot in my python file, or change the config json file with the user id, setting moderation = "True".
First of all, to "log in with discord" on your site you'll need to use discord's OAuth2. If you're storing your data in a json file (which I wouldn't recommend for scalability anyway), then you'll have to run you site from the same server as your bot and edit it there. However, you'd be better of in both ways using a cloud-hosted database such as PostgreSQL (SQL) or MongoDB (noSQL). Both of those can either be hosted locally on your machine, or by them in the cloud for free. Personally, I prefer MongoDB. That way you can run your site from wherever and update your database.
I have some python scripts which perform some jobs based on the user inputs I want to host this on microsoft teams. For an outgoing webhook teams asks for a https link where and how do I get it. I am pretty new to this so do not take anything for granted.
Basically, this "outgoing webhook" means that Teams has the ability to call a web service of some sort, hosted on a publicly-accessible https address. In the end, it functions very similarly to a bot, so it's possible to just create a full-blown bot. Here's guidance on creating a Microsoft bot (for Teams or otherwise) using Python.
However, there's a more simple option, of basically just hosting a web function somewhere (e.g. an Azure Function or, I guess, an Amazon Lamba). See this article. As mentioned in this link:
Outgoing webhooks post data from Teams to any chosen service capable
of accepting a JSON payload. Once an outgoing webhook is added to a
team, it acts like bot, listening in channels for messages using
#mention, sending notifications to external web services, and
responding with rich messages that can include cards and images.
An Azure Function automatically gets a full, unique, https address, so it's fine to use.
As another example, this blog post describes how to create a Flow ("Power Automate") that the webhook calls into. This example also ends up using an Azure Function to "glue together" Teams + Flow, but it explains the concepts a bit. You could ignore Flow and just use an Azure Function.
Whether to build an -actual- bot depends on -what else- you might want to be able to do. For instance, do you want to have a more complete conversation with the user? Do you want to the user to be able to interact with your code outside of a channel (e.g. a 1-1 conversation)? These are the kinds of things that will indicate if you might need a proper bot.
You need to use bot framework to create bot that will handle that:
https://github.com/microsoft/botframework-sdk
https://github.com/microsoft/BotBuilder-Samples
TLDR: I have a slack app for managing private channels in its development workspace and tokens for it that inherit my user privileges. How can someone else in the same workspace obtain tokens for this app that inherit their user privileges instead?
Ok, so the background of this is: i need to manage the membership of a bunch of private channels based on some more or less complicated ldap-related conditions. For this, i wanted to write a simple Python program that got the membership of the channels in question, did its ldap magic to figure out who should be where, and then make it so.
I have implemented this and all works fine so far. The issue now is that i (that is my slack user) cannot be in all of these channels for privacy reasons. The API and Bot tokens i have obtained inherit all of my own user privileges. That means i can neither see nor administrate the channels that i'm not a part of.
Based on what i've read in the documentation of the Slack API, there's a way to have another user go through the OAuth process for the app that i created to get the tokens, get their own tokens, and use them with the Python program that i wrote. That would be fine, but i can't figure out how to do this.
Noone else has access to the app directly. The documentation makes it seem like i need to give people a specially formatted link (the "Add to Slack Button") that they can click on to get taken through the process. But that seems to require a "redirect URL". I'm not sure what this is and the documentation isn't very clear on it, but it seems they are assuming that the app is running on a server somewhere and will need to answer requests from Slack or something. That's not the case. It's a fairly simple Python script, not some always-up cloud app that will be responding to Slack Events.
So it feels like i'm missing something. Either i have some fundamental misconception about how this is supposed to work, or there is a simple way for someone else to get a token like that and i'm not seeing it.
Yes. If you want other users to authenticate your app (e.g. generate tokens so your app can perform tasks on the users behalf) you need to create an installation routine using Ouath 2.0. That installation routine is a small web app that has the "Add to Slack" button, a HTML interface and is able to run through the Oauth 2.0 process. That web app needs to run on a public web server.
For development purpose that web server can also run on your local dev machine with a VPN tunnel to the public Internet. Slack recommends using the VPN service ngrok for that purpose.
Slack API provides you two options: use app as a bot and as a logged in user itself. I want to create App that will be working as a user and run channel commands. How can I do with discord.py?
Discord.py is no longer maintained to work on user accounts, so given the recent updates in the user api, it is no longer the ideal framework which selfbots should be written in.
There are a number of selfbot api libs out there, but the best one that's written in python is this: https://github.com/Merubokkusu/Discord-S.C.U.M
P.S. selfbotting against tos - so be careful (respect rate limits and don't act like a bot)
As Wright has commented, this is against discord's ToS. If you get caught using a selfbot, your account will be banned. However, if you still REALLY want to do this, what you need to do is add/replace bot.run('email', 'password') to the bottom of your bot, or client.run('email', 'password') to the bottom depending on how your bot is programmed.