This is a messenger API that sends messages from one user to another, it also stores messages for later retrieval. This app uses email as a vehicle to send messages, no one ever said this would be a fast process! HTML is also removed from any message.
Run: docker build -t chat:latest . --no-cache && docker run -e SENDGRID_API_KEY=<YOUR API KEY GOES HERE> chat
Note that the SENDGRID_API_KEY
you may have to create a Sendgrid account to obtain your own key
-
Make sure you have python3 and pip3 installed on your local environment
-
In the root level of your project run:
pip3 install -r requirements.txt
If that doesn't work dopip3 install <missing dependency that pip complains about>
-
For the
SENDGRID_API_KEY
environment variable set that locally on your machine (e.g.sudo export ENDGRID_API_KEY=<YOUR API KEY GOES HERE
).
##Running tests
The test cases assume that you have a server running on localhost:5000
, that can be changed by changing the testingUrl
variable at the top of the file.
From there run pytest server_test.py
or alternatively python3 server_test.py
Locally:
localhost:5000
, this can be changed in app.py in the main section
Useful for debugging and for kubernetes liveness probes
URL : /_status
Method : get
Code : 200 OK
Used to get all messages sent in the past 30 days or the last 100 messages if there are more than 100 messages sent in the past 30 days.
URL : /messages
Method : get
Auth required : NO
Code : 200 OK
Content example
[
{
"from": "[email protected]",
"message": "Hello there!",
"time": "2020-07-22 20:58:20.235556",
"to": "[email protected]"
},
{
"from": "[email protected]",
"message": "Hello there!",
"time": "2020-07-22 20:58:35.031935",
"to": "[email protected]"
}
]
Used to get all messages sent between two specified emails in the past 30 days or the last 100 messages if there are more than 100 messages sent in the past 30 days.
URL : /messages/user
URL Parameters : to=[string]
where to
is the email address that the message was sent to,
from=[string]
where from
is the email of the user that sent the email. Ex: /messages/[email protected]&[email protected]
Method : GET
Auth required : NO
Code : 200 OK
Content example
[
{
"from": "[email protected]",
"message": "Hello2 there!",
"time": "2020-07-22 14:14:08.548378",
"to": "[email protected]"
}
]
Condition : If either email isn't a valid email (e.g. [email protected] will work, bar.com will not)
Code : 400 BAD REQUEST
Used to send a Message from one user to another
URL : /message
Method : POST
Auth required : NO
Data constraints
{
"to": "[valid email address]",
"from": "[valid email address]"
}
Data example
{
"to": "[email protected]",
"to_name": "David Z",
"from_name": "David",
"from": "[email protected]",
"body": "Whatever you want"
}
Code : 200 OK
Content example
Condition : If either email isn't a valid email (e.g. [email protected] will work, bar.com will not)
Code : 400 BAD REQUEST