Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ Please read the overview for all code challenges [here.](http://atdevoutreach.vi
## Get Support on the Africa's Talking Slack
In case you have any questions, join our Slack [here](https://slackin-africastalking.now.sh/)


## Testing the app online
1. Launch the emulator from the [sandbox](https://account.africastalking.com/apps/sandbox/)
2. Set a test phone number on the simulator page and click on Launch
3. Select the SMS option and create a message
4. The message can have any content but you must send it to the number 9798
5. You will receive a message almost in no time :)


2 changes: 2 additions & 0 deletions sms_app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
__pycache__/
.env
1 change: 1 addition & 0 deletions sms_app/Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: gunicorn sms_app.wsgi --log-file -
Binary file added sms_app/db.sqlite3
Binary file not shown.
22 changes: 22 additions & 0 deletions sms_app/manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "sms_app.settings")
try:
from django.core.management import execute_from_command_line
except ImportError:
# The above import may fail for some other reason. Ensure that the
# issue is really that Django is missing to avoid masking other
# exceptions on Python 2.
try:
import django
except ImportError:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
)
raise
execute_from_command_line(sys.argv)
12 changes: 12 additions & 0 deletions sms_app/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
africastalking==1.1.4
certifi==2018.4.16
chardet==3.0.4
Django==1.11
gunicorn==19.8.1
idna==2.7
psycopg2-binary==2.7.4
pytz==2018.4
requests==2.19.1
schema==0.6.8
urllib3==1.23
whitenoise==3.3.1
1 change: 1 addition & 0 deletions sms_app/runtime.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python-3.5.2
Empty file added sms_app/server/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions sms_app/server/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
5 changes: 5 additions & 0 deletions sms_app/server/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class ServerConfig(AppConfig):
name = 'server'
Empty file.
3 changes: 3 additions & 0 deletions sms_app/server/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
3 changes: 3 additions & 0 deletions sms_app/server/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
29 changes: 29 additions & 0 deletions sms_app/server/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import os

from django.shortcuts import render
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
import africastalking



USERNAME = os.environ["USERNAME"]
API_KEY = os.environ["API_KEY"]

#initialize api
africastalking.initialize(USERNAME, API_KEY)

sms = africastalking.SMS

#we aren't using a form, so csrf isn't needed
@csrf_exempt
def sms_reply(request):
if request.method == "POST":
sender = request.POST["from"]
message = request.POST["text"] #get message content from sender

reply_message = "I am a fisherman. I sleep all day and work all night!"

sms.send(reply_message, recipients = [sender,], sender_id="9798")

return HttpResponse(status=200)
Empty file added sms_app/sms_app/__init__.py
Empty file.
130 changes: 130 additions & 0 deletions sms_app/sms_app/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
"""
Django settings for sms_app project.

Generated by 'django-admin startproject' using Django 1.11.

For more information on this file, see
https://docs.djangoproject.com/en/1.11/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.11/ref/settings/
"""

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'fxjko#ix64@r!c7ad92y7%qfmhhaygqsj#a9@2!6pq-l2j&+d2'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ['*']


# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'server'
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'sms_app.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'sms_app.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}


# Password validation
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]


# Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/

STATIC_ROOT = './static/'
STATIC_URL = '/static/'

# STATICFILES_DIRS = (
# os.path.join(BASE_DIR, 'static'),
# )

# for caching files and compression support
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'
23 changes: 23 additions & 0 deletions sms_app/sms_app/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""sms_app URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.11/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url
from django.contrib import admin
from server.views import sms_reply

urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^sms/', sms_reply, name="index")
]
19 changes: 19 additions & 0 deletions sms_app/sms_app/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""
WSGI config for sms_app project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application
from whitenoise.django import DjangoWhiteNoise

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "sms_app.settings")

application = get_wsgi_application()

application = DjangoWhiteNoise(application)
Loading