Python
This is walkthrough showing you how to connect Live Link 365's SMS sending API to a flight booking app. This sample creates the model of a flight's booking information and sends an SMS notification to a phone number.
This is not a production-ready application. Please take your time to enhance it for production so that it meets your specific business requirements.
Steps
Create the Python class for CustomerDetails
using the customerFirstName, customerLastName , customerMobNo and cUserName:
- customerFirstName: String
- customerLastName: String
- customerMobNo: String
- cUserName: String
-
Create the Python class for
FlightInformation
using fromCity, toCity, departureTime, arrivalTime, noOfSeatsBooked, totalNoOfSeats:- fromCity: String
- toCity: String
- departureTime: String
- arrivalTime: String
- noOfSeatsBooked: String
- totalNoOfSeats: String
-
Add
getAvailableSeatsAndAssign()
function checks available seats with FlightID using noOfSeatsbooked and noOfSeats and returns the seat assigned used by bookFlight function -
Add
bookFlight()
(customer) function -
Use customer parameter within
bookFlight()
to assign flight to that customer and send SMS
The config.ini
file acts as a temporary storage for records and holds key information such as: customer information (Name, Contact No, etc.), flight information (FlightID , fromCity, toCity, ArrivalTime, DepartureTime) and so on.
The config file can be replaced by a database holding the Customer
information
Before you can use the API for sending SMS, you have to fetch an authentication token, by providing:
- App key
- App secret
getAccessToken()
method will take the app key and secret and combine them into a Base64 string, which will then be sent to the /api/oauth/token
endpoint for generating the authentication token. Please visit this site's Authentication section for more info on app keys and secrets
On this step we create the method for sending an SMS:
- The
sendSMS()
method takes your message string, the destination phone number, and the authentication token generated by the method from the previous step
Now we finally call the main()
function, connecting the booking classes to the SMS API. Replace in the code:
- appKey: An app key
- appSecret: An app secret
- Finish by calling the
sendSMS.sendSMS()
method
Code
1 2 3 4 5 6 7 |
|
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 27 28 29 30 31 32 33 34 35 36 37 38 39 |
|
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 |
|
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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
|
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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
|