Chatbot to allow people to receive news from providers and submit their own stories.
- Node.js (see the "engines" property in package.json for supported versions).
- Npm package manager.
- Docker 17+ (for local testing)
- Ngrok (for local testing)
- MongoDB (if not using Docker for local testing)
When developing locally I like to use Docker (for environment encapsulation). I also use multiple terminal windows/tabs rather than starting all the Docker containers in one window as this makes it easier to read the application's terminal output.
You first need to create a local .env
file which will contain secrets and provider specific config (see Configuration files below).
- Open a terminal window and run ngrok with:
npm run ngrok
orngrok http 5000 --region eu -subdomain={{CUSTOM_SUBDOMAIN}}
. - Open a second terminal window and run MongoDB and MongoClient with:
docker-compose up mongodb mongoclient
. - Open a third terminal window and run the example chatbot with:
docker-compose up bot
.
You must use one of the "deploy" scripts to deploy Eyewitness automatically. For instructions on how to setup the hosting, please refer to the DEPLOY.md file.
Deployments need to be performed for:
- The Eyewitness bot and Read Server - using deploy commands in this repo.
- The UI in the Eyewitness UI repo
The deployment commands (described below) are identical for both repositories.
There are a number of configuration files for the different providers and environments (development/staging/production). The configuration files use a system of inheritance to avoid duplication, managed by the Config-Ninja package.
The config for development is app/config/development.config.json
which inherits from app/config/production.config.json
.
You may optionally add app/config/local.config.json
to override the standard development configuration.
No secrets or provider-specific configuration should be stored in the config files. These must be provided as environment variables. See ./app/modules/initConfig.js
for the full list of environment variables and the corresponding config names. See also empty.env
- this provides a starting point for creating a .env file for a specific environment.
Install Heroku CLI and then login:
heroku login
heroku container:login
To deploy one of the media providers' services to staging run the appropriate command:
npm run deploy-demo-staging
npm run deploy-battabox-staging
npm run deploy-sabc-staging
npm run deploy-thestar-staging
or to deploy all:
npm run deploy-all-staging
To deploy one of the media providers' services to production run the appropriate command:
npm run deploy-demo-production
npm run deploy-battabox-production
npm run deploy-sabc-production
npm run deploy-thestar-production
or to deploy all:
npm run deploy-all-production
After deploying to a staging or production environment you should check it is working.
To verify the bot:
- Find the provider name from the bot config file for the provider.
- Search for the bot with that name on Facebook messenger (you need to be given access for non-production environments)
- You can then type
$whoami
or$debug
to check version info, and chat to the bot to test features that were changed.
To verify the UI:
- Find the URL for the UI in the
uiServer
property of the bot config file for the provider. - Open the URL in the browser, log-in with the credentials under
basicAuth
from the config file in the UI repo - Also try appending
/health-check
the URL to check the version number.
Returns the total number of user documents in the database.
db.user.count()
Returns the total number of article documents in the database.
db.article.count()
Returns the aggregated number of article reads across all articles.
db.article.aggregate([
{ $unwind: "$_readByUsers" },
{ $group: { _id: {}, count: { "$sum": 1 } } },
{ $group: { _id: {}, numReads: { $push: { _readByUsers: "$_id.readByUsers", count: "$count" } } } }
])