Skip to content

This project demonstrates the power of the Twilio Messaging API in a CAP bookshop application.

License

Notifications You must be signed in to change notification settings

IObert/twilio-bookshop-management

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Twilio Bookshop Management

This sample project demonstrates how to combine the Twilio Messaging API with an application built with the SAP Cloud Application Programming Model. Basic information about this project can be found in this repository. For more details, please refer to the following blog post.

title image

The project builds on the well-established bookshop scenario and improves the user experience of the bookshop owner. Every time the stock of a particular book goes below a pre-defined threshold, a warning is sent to to a shop manager. If the manager then want to restock this item, they can simply reply to the text message to trigger that action. The Twilio platform will then invoke a webhook provided by this application to order more books.

Prerequisites

Optional: Visual Studio Code with the following extensions installed:

If you are running macOS or Linux, you will likely have SQLite installed. For Windows users, I recommend using the Chocolatey package manager to install sqlite via choco install sqlite. After the installation, please check you can start the executable (sqlite) from the terminal.

Getting started

  1. Clone this repository and navigate into it

    git clone https://github.com/IObert/twilio-bookshop-management.git
    cd twilio-bookshop-management
  2. To connect this project to your Twilio account, you need to include the account SID and the secret authentication token. It's crucial to keep them private and exclude them from the codebase you check into a git repository. So it makes sense to keep them in the environment variable of the project. In any CAP project, the default-env.json file is the perfect place for these secrets as it's already on the .gitignore list, and all properties are automatically loaded in the environment variables during startup. For this application, include the sender and receiver number of the text messages to the new file default-env.json as well:

    {
        "TWILIO_ACCOUNT_SID": "ACXXXXXXX",
        "TWILIO_AUTH_TOKEN": "1acYYYYY",
        "TWILIO_SENDER": "+18600000000",
        "TWILIO_RECEIVER": "+18600000000"
    }
  3. Install all dependencies and start the server

    npm install
    npm start
  4. Start ngrok

    ngrok http 4004

    ngrok

    Alternatily, you can also deploy the app to the cloud and use the URL of the deployed app

  5. Go to the Twilio Console and navigate to your phone number. Add the HTTPS URL that the previous step printed with the /twilioWebhook suffix to the section “A message comes in”. webhook

  6. Trigger a request to order 95 books which results in a warning message to your phone number low-stock

  7. Let's give it a shot. Respond with "Yes, please order 100 additional books" to the message you received a few minutes ago. Now query the current stock info via the first HTTP request once more. restocked

Known Issues

If this weren't just a demo but a production app, it would make sense to add proper state management to the application to save which book needs to be reordered instead of extracting this information from the initial text message.

Get Support

Check out the relevant documentation at twilio.com/docs/sms and cap.cloud.sap.
If you have a question, find a bug, or otherwise need support, please open an issue in this repository.

License

This project is licensed under the Apache Software License, version 2.0, except as noted otherwise in the LICENSE file.

About

This project demonstrates the power of the Twilio Messaging API in a CAP bookshop application.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published