Skip to content

scasBot/texting-service

Repository files navigation

SCAS Client Texting Service

A web app that programmatically follows up with clients within a specified time frame!

Quickstart

Local development

This project is built using the Flask web framework. It runs on Python 2.7+ and Python 3.4+.

To run the app locally, first clone this repository and cd into its directory. Then:

  1. Create a new virtual environment with Python 2.7:

    • If using vanilla virtualenv:

      $ virtualenv -p /usr/bin/python2.7 venv
      $ source venv/bin/activate
    • If using virtualenvwrapper:

      $ mkvirtualenv appointment-reminders
  2. Install the requirements:

    $ pip install -r requirements.txt
  3. Start a local PostgreSQL database and create a database called clients:

    • If on a Mac, we recommend Postgres.app. After install, open psql and run CREATE DATABASE clients;
    • If Postgres is already installed locally, you can just run createdb clients from a terminal
  4. Copy the .env_example file to .env, and edit it to include your credentials for the Twilio API (found at https://www.twilio.com/user/account/voice) and your local Postgres database

  5. Run source .env to apply the environment variables (or even better, use autoenv)

  6. Run the migrations with:

    $ alembic upgrade +1

    Note: If you have a local postgres installation where you access without password add this line to your pg_hba.conf file, JUST FOR DEVELOPMENT, DO NOT USE THIS IN PRODUCTION: host all YOUR_USER 127.0.0.1/32 trust

  7. Start a redis server to be our Celery broker. If on a Mac, we recommend installing redis through homebrew

    $ brew install redis
    $ redis-server
  8. Start the development server:

    $ python runapp.py

You can now access the application at http://localhost:5000. To send any follow-ups, however, you must also start a separate Celery worker process.

  1. Start a new terminal session, cd into the repository, and activate your appointment-reminders virtualenv

  2. Start the Celery worker:

    $ celery -A reminders.celery worker -l info

Celery will now send SMS reminders for any new clients you add through the web app.

  1. Start an ngrok tunnel in a new tab:

    $ ./ngrok http 5000

This tool makes our application, which is currently just running locally on our computer, accessible over the internet. In order to respond to incoming texts, we need to forward requests to our development environment, and that's what ngrok allows us to do. Update the address on the Twilio console to the forwarding address displayed in the terminal (should be in the form https://bb0fa28a.ngrok.io/sms) here by clicking the phone number and changing the messaging webhook.

Run the tests

You can run the tests locally through pytest.

Follow the instructions in the Local Development section above, and then run:

$ py.test --cov tests

You can then view the results with coverage report or build an HTML report with coverage html.

Meta

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published