- RETRIEVE AUTH TOKEN FROM SLACK CLIENT UPGRADE
- RETRIEVE AUTH TOKEN FROM SLACK CLIENT CODE
- RETRIEVE AUTH TOKEN FROM SLACK CLIENT FREE
Woohoo, all done! Well actually, there’s a whole lot more you can do with the Slack and Twilio APIs. This is a great hook for expanding our bot or sending messages to another service for processing.
RETRIEVE AUTH TOKEN FROM SLACK CLIENT CODE
Sweet! That’s pretty simple output but we have a basic way to receive messages from one or more channels and can add whatever Python code we want to handle the input. Send a message mentioning twiliobot like hola!” and hit enter. You should see that the outgoing webhook integration has been added to the channel. Restart your Flask server because it’s time to test out receiving messages via SMS! Twilio_(to=USER_NUMBER, from_=TWILIO_NUMBER,
Response_message = username + " in " + channel + " says: " + text Return Response(response.toxml(), mimetype="text/xml"), methods=) Slack_client.api_call("chat.postMessage", channel="#general", Slack_client = SlackClient(os.environ.get('SLACK_TOKEN', None)) USER_NUMBER = os.environ.get('USER_NUMBER', None) TWILIO_NUMBER = os.environ.get('TWILIO_NUMBER', None) SLACK_WEBHOOK_SECRET = os.environ.get('SLACK_WEBHOOK_SECRET', None) Add the new highlighted line and the highlighted function shown below.įrom flask import Flask, request, Responseįrom _response import MessagingResponse Stop the Flask development server with “Ctrl-C” and modify the existing twiliobot.py file. However, what if we want to see when someone mentions “twiliobot” in a channel? We can set up an outgoing Slack webhook that’ll alert our Python application via an HTTP POST request. Our bot can take SMS messages coming to our Twilio phone number and post them as messages to a Slack channel. Our Flask web app then uses slackclient to post a message to our Flask channel as twiliobot, just like we see here:Ĭool, we can send messages to Slack! Next let’s get important messages out of Slack and sent to our phone via SMS. Then ngrok will forward the POST request to your local machine, which will hit your running twiliobot.py Flask development server. The SMS will go to Twilio, Twilio will send an HTTP POST request to the ngrok URL you configured in the phone number configuration screen. Send a text message to your Twilio phone number.
RETRIEVE AUTH TOKEN FROM SLACK CLIENT FREE
To expose my local web server via an externally-accessible domain I typically use ngrok since it’s easy, free and awesome.ĭownload ngrok and run it with this command: During development our application is typically running on our local server which cannot be reached from anywhere except our local machine. Twilio needs a reachable URL to send an HTTP POST request to when an SMS is sent to our Twilio phone number. Click the phone number you want to use for the bot to configure it.
RETRIEVE AUTH TOKEN FROM SLACK CLIENT UPGRADE
If you already have an account you can use your existing Twilio phone number or upgrade your account to buy a new number. When you sign up for a new account you’ll be given a Twilio phone number. Sign up for a free Twilio account or log into your existing account if you already have one. We need access to the Twilio API to send and receive SMS messages. We just need a Twilio account and credentials to create our bot! Sending SMS Messages to Slack Within that directory, create a new virtualenv to isolate our application dependencies from other Python projects you’re working on.Īwesome, we’re authorized to start using the Slack API through our account. Now that we know what tools we need to use, go to the terminal (or Command Prompt on Windows) and change into a directory where you want to store this project. You can follow along by writing the code in this post or skip ahead to the finished project by cloning the companion GitHub repository. We will configure everything else throughout the remainder of this tutorial.
Make sure Python version 2 or 3 is installed now.