Python

This application will demonstrate how to implement endpoints to start receiving callbacks from Live Link 365.

This is not a production-ready application, please take your time to read about Flask to make it meet production standards and your business requirements.

To follow this tutorial, you should have basic understanding of:
  • Python
  • Flask
  • Pipenv
  • Requests

Steps

Code

keyboard_arrow_down
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# _Step_1
from callbacks.config import config_env_files
from flask import Flask

app = Flask(__name__)

def prepare_app(environment='development'):
    app.config.from_object(config_env_files[environment])
    from . import appointmentsService
    return app
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
# _Step_2
import os

basedir = os.path.abspath(os.path.dirname(__file__))

class DefaultConfig(object):
    DEBUG = False
    LIVELINK_APP_KEY = ""
    LIVELINK_APP_SECRET = ""
    LIVELINK_BASE_URL = "ttps://livelink.sapdigitalinterconnect.com/api"
    LIVELINK_DEFAULT_ORIGIN = ""

class DevelopmentConfig(DefaultConfig):
    DEBUG = True
    LIVELINK_APP_KEY = "",
    LIVELINK_APP_SECRET = "",
    LIVELINK_BASE_URL = "",
    LIVELIN_DEFAULT_ORIGIN = ""

config_env_files = {
    'development': 'callbacks.config.DevelopmentConfig',
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# _Step_3
from flask import Flask, request
from flask_restful import Resource, Api
from .appointmentsService import AppointmentService
# from . import app

app = Flask(__name__)

@app.route("/messages/status", methods=["POST"])
def StatusPost():
    print(request.json['message'])
    return "Status - OK";

@app.route("/messages/incoming", methods=["POST"])
def IncomingPost():
    message = "\nMessage Response for message order " + request.json['messageId'] + "\nFrom Phone Number: " + request.json['msisdn'] + "\nResponse Text: " + request.json['message'] + "\nOperator Standard: " + request.json['parameters']['operator']['standard'] + "\nReceived on " + request.json['receivedTime']['Date'] + " at " + request.json['receivedTime']['Time']
    print(str(message))
    return "Incoming - OK"

# _Step_5
if __name__ == '__main__':
    app.run();
    appointmentsService = AppointmentService();
    appointmentsService.sendAppointmentMessage();
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from .messageHandler import MessageHandler
from .models import *
from dateutil.parser import parse
import configparser
import datetime
import json

# _Step_4
class AppointmentService():
    def __init__(self):
        self.doctor = Doctor(1, "Christina", "Yang", "Cardiology")
        self.patient = Patient(2, "Steven", "Gorwell", "+50431401307")
        self.appointment = Appointment(doctor, patient, parse("2018-08-11T04:00"))

    def sendAppointmentMessage(self):
        print("HI")
        patientName = self.appointment.patient.patientName
        doctorName = self.appointment.doctor.doctorName
        specializationName = self.appointment.doctor.specialization
        appointmentDate = self.appointment.date
        strAppointmentDate = self.appointmentDate.strftime('%b %d, %Y')

        appointmentMessage = "Mr./Mrs. " + patientName + ", you have an appointment with Dr. " + doctorName + " (" + specializationName + ")" + " scheduled on " + strAppointmentDate
        destinationNumber = self.appointment.patient.number
        messageHandler = MessageHandler()
        messageHandler.sendSMS(appointmentMessage, destinationNumber)