![]() ![]() User_id, message = parse_direct_mention ( event ) If event = " message" and not " subtype" in event: If its not found, then this function returns None, None. If a bot command is found, this function returns a tuple of command and channel. Parses a list of events coming from the Slack RTM API to find bot commands. Next, add three new functions above the previous snippet to We've laid the groundwork for processing Slack events and calling Slack methods If it does, then command willĬontain a value and the handle_command() function determines what The event contains a command for Starter Bot. Notice thatīefore the loop ends, the program pauses for one second so that it doesn't loopįor each event that is read, the parse_bot_commands() function determines if Next, the program enters an infinite loop, where each time the loop runs theĬlient recieves any events that arrived from Slack's RTM API. Storing this user ID will help the program understand if someone has Once it's connected, it calls aĮach bot user has a user ID for each workspace the Slack App is installed The Slack client connects to the Slack RTM API. Handle_command ( command, channel ) time. api_call (" auth.test" )Ĭommand, channel = parse_bot_commands ( slack_client. # Read bot' s user ID by calling Web API method `auth.test` starterbot_id = slack_client. Print (" Starter Bot connected and running!" ) Back in your terminal, export the Slack token with the It displays a bot user oauth access token for authentication as the bot user.Ī common practice for Python developers is to export secret tokens asĮnvironment variables. Will install the App into our Development Workspace. We'll use both to implement Starter Bot, and they each require authentication.Ĭonveniently, the bot user we created earlier can be used to authenticate forĬlick on the "Install App" under the "Settings" section. The slackclient library makes it simple to use Slack's You'llĮnd up with a page that looks like the following: ![]() AfterĬlicking "Add a Bot User", you should choose a display name, choose aĭefault username, and save your choices by clicking "Add Bot User". We set up by choosing "Bot Users" under the "Features" section. Participate in conversations inside channels, groups, and DMs. We want our Starter Bot to appear like any other user in your team - it will Into more than one workspace, pick a Development Workspace from the dropdown.Īfter submitting the form, keep the app configuration page open. We also need to create a Slack App to recieveĪn API token for your bot. When pip is finished you should see output like this and you'll be That directory, create a new virtualenv to isolate our application Go to the terminal (or Command Prompt on Windows) andĬhange into the directory where you want to store this project. We now know what tools we need for our project so let's get our developmentĮnvironment set up. It is also useful to have the Slack API docs handyĪll the code for this tutorial is available open source under the MIT license Least one workspace where you have access to building apps.
0 Comments
Leave a Reply. |