Skip to content

Commit 583c58b

Browse files
authored
Merge pull request #11 from FreeClimbAPI/docker
Added dockerfile, actions and other minor changes
2 parents 350d7b3 + 4c6744c commit 583c58b

File tree

8 files changed

+175
-51
lines changed

8 files changed

+175
-51
lines changed

.dockerignore

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Include any files or directories that you don't want to be copied to your
2+
# container here (e.g., local build artifacts, temporary files, etc.).
3+
#
4+
# For more help, visit the .dockerignore file reference guide at
5+
# https://docs.docker.com/go/build-context-dockerignore/
6+
7+
**/.DS_Store
8+
**/__pycache__
9+
**/.venv
10+
**/.classpath
11+
**/.dockerignore
12+
**/.env
13+
**/.git
14+
**/.gitignore
15+
**/.project
16+
**/.settings
17+
**/.toolstarget
18+
**/.vs
19+
**/.vscode
20+
**/*.*proj.user
21+
**/*.dbmdl
22+
**/*.jfm
23+
**/bin
24+
**/charts
25+
**/docker-compose*
26+
**/compose*
27+
**/Dockerfile*
28+
**/node_modules
29+
**/npm-debug.log
30+
**/obj
31+
**/secrets.dev.yaml
32+
**/values.dev.yaml
33+
LICENSE
34+
README.md

.env.sample

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Configure Environment Variables and Rename this file to .env
2+
ACCOUNT_ID=
3+
API_KEY=
4+
5+
FREECLIMB_NUMBER=+1

.github/workflows/main.yml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Build and Push Image to DockerHub
2+
3+
on:
4+
push:
5+
branches:
6+
- 'master'
7+
8+
jobs:
9+
dockerhub:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: check repository
13+
uses: actions/checkout@v4
14+
- name: login to docker registry
15+
uses: docker/login-action@v3
16+
with:
17+
username: ${{secrets.DOCKER_USERNAME}}
18+
password: ${{secrets.DOCKER_PASSWORD}}
19+
- name: lowercase github.repository
20+
run: |
21+
echo "IMAGE_NAME=`echo ${{github.repository}} | tr '[:upper:]' '[:lower:]'`" >>${GITHUB_ENV}
22+
- name: build and push
23+
uses: docker/build-push-action@v5
24+
with:
25+
context: .
26+
push: true
27+
tags: ${{ env.IMAGE_NAME }}:latest
28+
- name: update docker hub description
29+
uses: peter-evans/dockerhub-description@v4
30+
with:
31+
username: ${{ secrets.DOCKER_USERNAME }}
32+
password: ${{ secrets.DOCKER_PASSWORD }}
33+
repository: ${{ env.IMAGE_NAME }}

Dockerfile

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM python:3.12
2+
3+
WORKDIR /Python-SMS-Quickstart
4+
5+
# Copy requirements.txt
6+
COPY requirements.txt requirements.txt
7+
8+
# Install dependencies
9+
RUN pip3 install -r requirements.txt
10+
11+
# Copy the source code into the container
12+
COPY . .
13+
14+
# Run the application.
15+
ENTRYPOINT ["python3", "main.py"]

Python-SMS-Quickstart.py

-35
This file was deleted.

README.md

+26-11
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,19 @@ Tools:
3535
pip install -r requirements.txt
3636
```
3737

38-
2. Configure environment variables:
38+
2. Configure environment variables (in `.env.sample` and rename the file to `.env`):
3939

40-
| ENV VARIABLE | DESCRIPTION |
41-
| ------------ | -------------------------------------------------------------------------------------------------------------------------------------- |
42-
| ACCOUNT_ID | Account ID which can be found under [API credentials](https://www.freeclimb.com/dashboard/portal/account/authentication) in dashboard. |
43-
| API_KEY | API key which can be found under [API credentials](https://www.freeclimb.com/dashboard/portal/account/authentication) in dashboard. |
40+
| ENV VARIABLE | DESCRIPTION |
41+
| ---------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
42+
| ACCOUNT_ID | Account ID which can be found under [API credentials](https://www.freeclimb.com/dashboard/portal/account/authentication) in dashboard. |
43+
| API_KEY | API key which can be found under [API credentials](https://www.freeclimb.com/dashboard/portal/account/authentication) in dashboard. |
44+
| FREECLIMB_NUMBER | The number that sends messages from your application. Your FreeClimb number. |
4445

45-
3. Replace placeholder value for the `from` number in `Python-SMS-Quickstart.py`:
46-
47-
| VARIABLE | DESCRIPTION |
48-
| -------- | ---------------------------------------------------------------------------- |
49-
| FROM | The number that sends messages from your application. Your FreeClimb number. |
46+
3. Make your local server publicly accessible
47+
```bash
48+
ngrok http 3000
49+
```
50+
Once you run ngrok you should receive a response with a public URL, that looks something like 'https://ba1c-63-209-137-19.ngrok-free.app'.
5051

5152
4. [Configure your applications's endpoints](https://docs.freeclimb.com/docs/registering-and-configuring-an-application#configure-your-application) by adding a publicly accessible URL (we recommend an [ngrok](https://ngrok.com/download) URL) and the route reference `/incomingSms` to your App Config's SMS URL field:
5253

@@ -59,11 +60,25 @@ Tools:
5960
1. Start your voice quickstart application
6061

6162
```bash
62-
env FLASK_APP=Python-SMS-Quickstart.py flask run
63+
python main.py
6364
```
6465

6566
2. Text the FreeClimb number assigned to the application you've configured for this tutorial
6667
68+
## Using Docker to Run the Quickstart
69+
70+
1. Pull docker image from dockerhub
71+
72+
```bash
73+
docker pull freeclimbapi/python-sms-quickstart
74+
```
75+
76+
2. Run docker image after replacing placeholder values
77+
78+
```bash
79+
docker run -e ACCOUNT_ID=<YOUR_ACCOUNT_ID> -e API_KEY=<YOUR_API_KEY> -e FREECLIMB_NUMBER=<YOUR_FREECLIMB_NUMBER> -p 3000:3000 freeclimbapi/python-sms-quickstart
80+
```
81+
6782
## Feedback & Issues
6883
6984
If you would like to give the team feedback or you encounter a problem, please [contact support](https://www.freeclimb.com/support/) or [submit a ticket](https://freeclimb.com/dashboard/portal/support) in the dashboard.

main.py

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import freeclimb
2+
from freeclimb.api import default_api
3+
from flask import Flask, request, jsonify
4+
import os
5+
from dotenv import load_dotenv
6+
7+
load_dotenv()
8+
account_id = os.environ.get("ACCOUNT_ID")
9+
api_key = os.environ.get("API_KEY")
10+
api_server = os.environ.get("API_SERVER", "https://www.freeclimb.com/apiserver")
11+
from_number = os.environ.get("FREECLIMB_NUMBER")
12+
13+
if not account_id or not api_key or not from_number:
14+
print("ERROR: ENVIRONMENT VARIABLES ARE NOT SET. PLEASE SET ALL ENVIRONMMENT VARIABLES AND RETRY.")
15+
quit()
16+
17+
app = Flask(__name__)
18+
19+
configuration = freeclimb.Configuration(
20+
host=api_server,
21+
username=account_id,
22+
password=api_key
23+
)
24+
25+
api_client = freeclimb.ApiClient(configuration)
26+
api_instance = default_api.DefaultApi(api_client)
27+
28+
# Specify this route with 'SMS URL' in App Config
29+
@app.route('/incomingSms', methods=['POST'])
30+
def incomingSms():
31+
if request.method == 'POST':
32+
message = "Hello World!"
33+
_from = from_number #Your FreeClimb Number
34+
to = request.json['from']
35+
message_request = freeclimb.MessageRequest(_from=_from, text=message, to=to)
36+
api_instance.send_an_sms_message(message_request)
37+
return jsonify({'success':True}), 200, {'ContentType':'application/json'}
38+
39+
# Specify this route with 'STATUS CALLBACK URL' in App Config
40+
@app.route('/status', methods=['POST'])
41+
def status():
42+
return jsonify({'success':True}), 200, {'ContentType':'application/json'}
43+
44+
45+
def quickstart_tutorial():
46+
obfuscated_api_key = '*'*(len(api_key) - 4)+api_key[-4:]
47+
48+
print("\nWelcome to FreeClimb!\n")
49+
print("Your account id: {0}".format(account_id))
50+
print("Your api key is: {0}\n".format(obfuscated_api_key))
51+
print("Your web server is listening at: http://127.0.0.1:3000")
52+
print("Your NEXT STEP is to use NGROK to proxy HTTP Traffic to this local web server.")
53+
print("\t1. In NGROK, configure the dynamic url to proxy to http://127.0.0.1:3000")
54+
print("\t2. In the Dashboard or API, set your FreeClimb Application Voice Url to the dynamic endpoint NGROK generated.\n")
55+
print(api_server)
56+
57+
58+
if __name__ == '__main__':
59+
quickstart_tutorial()
60+
app.run(host='0.0.0.0', port=3000)

requirements.txt

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
urllib3 >= 1.15.1
2-
certifi >= 14.05.14
3-
six >= 1.10
4-
python-dateutil >= 2.5.3
5-
Flask >= 2.3.2
61
freeclimb >= 4.4.0
2+
Flask>=2.3.2
3+
python-dotenv

0 commit comments

Comments
 (0)