A self-hosted Cisco Spark bot for taking surveys.
-
Create a new user on Cisco Spark to be the bot. Admittedly, it's untraditional to use a user account, but because of the way the bot works, it needs to be a user and cannot be a bot or an integration.
-
Once you create a user, go log in at Cisco Spark for Developers
-
Click on your avatar in the top right hand corner to show your Access Token.
-
Copy that token and use it as your
ACCESS_TOKENenvironment variable.
-
-
As that new user, create an integration:
-
App icon
Feel free to use this image URL.
-
Redirect URI(s)
You'll want this to be the
PUBLIC_ADDRESSenvironment variable with/auth/spark/callbackat the end.E.g.
https://my-test-survey-bot.herokuapp.com/auth/spark/callback -
Scopes
Choose the following scopes:
Scope Reason for needing it spark:people_readso OAuth can fetch user info (name, avatar, etc...) spark:rooms_readfor letting you choose a room to survey spark:memberships_readfor knowing who is in a room spark:messages_writefor sharing survey results spark:teams_readfor letting you choose a team room to survey -
Once you create the integration, grab the Client ID and Client Secret. These will be the environment variables
SPARK_OAUTH__CLIENT_IDandSPARK_OAUTH__CLIENT_SECRET.
-
-
Set the following environment variables. If developing locally, you can put these in the
.envor.env.localfiles:Environment variable Description PUBLIC_ADDRESSthe address at which your bot can be reached ACCESS_TOKENthe access token from the user you created SPARK_OAUTH__CLIENT_IDthe client id of the integration you created SPARK_OAUTH__CLIENT_SECRETthe client secret of the integration you created SPARK_SECRETsecret for validating the origin of webhooks and for encrypting cookies. Generate a random string for this value. If you are using Heroku, this will be generated for you if you use the "Deploy to Heroku" button. In development, feel free to ignore this as one will be generated for you but it will be different every time your app starts. REDIS_URLURL of your Redis server. If you are using Heroku, this will be added for you. PORTthe port to run the web server. If you are using Heroku, this will be added for you. RESTRICT_LOGINS_TO_DOMAINSonly allow users to log in if they match certain domains. Set to a comma separated list of allowed domain names. E.g. example.com,example.net,email.example.biz. Must provide the full domain-- e.g.bob@mail.example.comwill not be allowed to log in if your list isexample.com. If not set, it will allow logins with any domain name.
Use the "Deploy to Heroku" button above from this repo or a fork of this repo.
A Dockerfile has been included to run the bot via Docker. Here are some additional instructions for running the bot via Docker locally.
Put your environment variables in .env.local and run via:
docker build -t my-survey-bot .
docker run -it --env-file .env.local my-survey-bot
-
Follow the instructions in Setup & Configuration above, with the following notes:
- Set your
PUBLIC_ADDRESSenv variable to your ngrok URL, e.g.http://sparksurvey.ngrok.io - The
SPARK_SECRETis not needed in development. - Set the
ALLOW_DEV_LOGINto1to let you log into the app without needing an internet connection. This will let you create and modify surveys, but will not let you conduct surveys.
- Set your
-
Install dependencies
yarn install -
Start the local development server & redis:
yarn startIf you already have Redis running as a deamon or aren't using a local Redis server, do:
yarn server-dev -
If using Docker, you can run the image specifying the environment file and exposing port 3000:
docker run -it --env-file .env.local --publish 3000:3000 my-survey-bot -
Run ngrok (or something like it).
Because Spark uses webhooks to talk to bots, you must run something like ngrok locally to expose your server to the web. We've included a script to do this for you (requires ngrok).
yarn ngrok -
Add a Redirect URI to your Spark Integration settings that uses your ngrok URI. E.g.
https://sparksurvey.ngrok.io/auth/spark/callback
Run the tests:
yarn test
Run the linter:
yarn lint
Run the test watcher, which will re-run tests after every file change:
yarn test-watch




