- The API url used by default is
https://api.catapult.inetwork.com/
. Change it tohttps://messaging.bandwidth.com/api
instead. - Change some environment variable names to be more relevant.
- Remove the
applicationId
from the message payload before writing it to the database. - Remove annoying automatic prefixing of "+1" with phone numbers.
- Update client to have a separate text input for the
From
number. - Update server to work with multiple
From
numbers.
This app demonstrates how you can build a small server that works with Bandwidth's Messaging API. It will send and receive messages, store them and retrieve them, provide conversation threading, and provide a web interface that updates in realtime.
To use this sample, you will need a Messaging-enabled Bandwidth Account, and a MariaDB database to store your messages. This guide assumes that you already have MariaDB set up, and an empty schema called messaging
created for use with this app. You will also need Node.js installed to run this sample.
Download the source code:
$ git clone https://github.com/BandwidthExamples/messaging-sample-app.git
$ cd messaging-sample-app
You will need to fill in the appropriate values for your database connection, and API credentials in the .env
file in the root of the project directory.
PORT=5000
USERNAME=messaging
DATABASE_HOST=127.0.0.1
DATABASE_PORT=3306
DATABASE_USERNAME=root
DATABASE_PASSWORD=
DATABASE_NAME=messaging
BANDWIDTH_ACCOUNT_ID=
BANDWIDTH_API_TOKEN=
BANDWIDTH_API_SECRET=
APPLICATION_ID=
APPLICATION_FROM_NUMBERS=<'from' phone numbers>
Start the docker-compose
stack in pony-formation/docker/my-little-phoney/docker-compose.local.yml
with docker-compose -f docker-compose.local.yml up db
. This will start a MariaDB service on port 3306.
$ npm run install:all
$ cd client
$ npm build
$ cd ..
$ npm start
Server listening on port 5000
Open a web browser and point it to http://localhost:5000