How to set up Cat Facts on your own device
Requirements:
- An Android phone with SMS capabilities
- Tasker (Android app for automation)
- Node.js
- Heroku CLI for deployment
Copy the repository into your workspace:
-
Clone the repository from GitHub
git clone https://github.com/alexwohlbruck/cat-facts.git
-
Install NPM modules
npm install
Set up services and APIs
- Create your service tokens
- Heroku Hosting (Skip this if you want to use your own web hosting)
- Log in or Sign up at https://heroku.com
- Create a new app and name it whatever you like. This name has to be unique and not in use
- You can either connect the app to a GitHub repository or use Herokuâs own Git service via the CLI:
- With the Heroku CLI: Follow the instructions on the Deploy tab in Heroku
- With Connect to GitHub: Sign into GitHub and pick your repository to connect. Enable auto-deploys if youâd like
- Google Developers Platform (For Google Sign in and OAuth)
- Log in to https://console.developers.google.com
- Create a new project and name it âCat Factsâ
- In the Dashboard, click âEnable APIâ. Here you can search for APIs needed for the project
- Enable the Google+ API and the Google People API
- Go the the Credentials section and create an OAuth 2.0 Client ID
- Add the domain name where your project is hosted as an Authorized Javascript Origin, for example:
https://cat-fact.herokuapp.com
If youâre using Heroku for hosting, the domain should behttps://your-app-name.herokuapp.com
- In the Authorized redirect URIâs section, add two more URLs with the callback URLS like so:
https://{what-ever-you-used-as-the-domain-above}.com/auth/google/callback
https://{what-ever-you-used-as-the-domain-above}.com/auth/google/contacts/callback
- Take note of the Client ID and Client Secret, weâll use them later
- IFTTT (Communication from server to your device)
- Download the IFTTT app to your Android phone and sign in
- Connect the Maker Webhooks and Android SMS services to your account
- Add the CatBot Applet and turn it on
- Go to the Maker Webhooks page and click âDocumentationâ
- Take note of your service key, displayed at the top
- mLab MongoDB database (Skip this if you want to use your own Mongo database)
- Sign up or log in to mLab
- Create a new database by clicking the âCreate newâ button
- Choose the AWS Provider and under the Single-node tab, choose the free Sandbox option
- Name your database âcat-factsâ and create it
- Open the database and create a user for your database. Remember the username and password (this is different than the user/pass combo you used to login to mLab)
- Api.ai account (For conversational chatbot)
- Visit Api.aiâs website and sign in using your Google account
- Download the Cat Facts Api.ai agent from Google Drive
- Create a new agent and name it âCat Factsâ
- Once itâs created, click on the gear by the agent name to access itâs settings
- Under the âExport and Importâ tab, click âRestore from ZIPâ and upload the agent file. You should now have access to the full dashboard.
- Now go to the âGeneralâ tab and keep note of the client access token. You will need this for later as well.
- Under the âFufillmentâ section of the console, make sure webhook is enabled, and update the URL to the same domain name you used earlier, followed by
/webhook
, example:https://{what-ever-you-used-as-the-domain-above}.com/webhook
- Heroku Hosting (Skip this if you want to use your own web hosting)
- Add tokens and other credentials to your config vars
-
Add the following config variables to your project (In the Settings tab of the Heroku console and in your development environment if you want to use one):
Name Value APIAI_ACCESS_TOKEN {Your api.ai access token} BASE_URL {Your heroku appâs domain name} DB_USERNAME {Your mLab databaseâs user account name} DB_PASSWORD {Your mLab databaseâs user account password} ENCRYPTION_ALGORITHM aes-256-ctr
ENCRYPTION_KEY {Generate a key using the password generator} GENERAL_ACCESS_TOKEN {Generate a key using the password generator} GOOGLE_CLIENT_ID {Your Client ID from the Google Developerâs Platform GOOGLE_CLIENT_SECRET {Your Client Secret from the Google Developerâs Platform} IFTTT_API_KEY {The service key provided by the IFTTT Maker Webhooks service} NODE_ENV {âproductionâ for your heroku config and âdevelopmentâ for your own development environment} SESSION_SECRET {Generate a key using the password generator}
LastPass Random Password Generator: https://lastpass.com/generatepassword.php
-
- Deploy your app
- In the Deploy tab of the Heroku console, re-deploy the app, and check itâs status in the Activity tab
- You should be able to visit your Cat-Facts clone at the domain you have been using
- To test that itâs working, try to sign in. If all is well, continue to the next step
Connect your phone to Cat Facts
- Set up Tasker automation
Tasker is an Android app that can help you automate your phone based on âProfilesâ and âTasksâ. Download the app to your Android phone and follow the instructions below:
- Create a new Profile by clicking the plus button, and choose Time
- In the âfromâ section, choose a time for the Cat Facts to send every day. Then disable the âtoâ option
- Click the back button, and on the next screen click âNew Taskâ
- Name the task âCatBot Manyâ and click the Check box
- Add the following actions to this task:
- HTTP Get
- Server:Port:
{Your heroku app's domain name}
- Path:
/catbot/daily
- Attributes:
code={Your general access token from config vars}
- Server:Port:
- JavaScriptlet
- Code:
var data = JSON.parse(global('HTTPD')); var recipients = data.recipients.join(','); var fact = data.fact; setGlobal('DAILYFACT', fact); setGlobal('RECIPIENTS', recipients);
- Code:
- For
- Variable:
%RECIPIENT
- Items:
%RECIPIENTS
- Variable:
- Send SMS
- Number:
%RECIPIENT
- Message:
%DAILYFACT
- Number:
- Wait
- Seconds: 2
- End For
- HTTP Get
- Go back to the Profiles tab and create an event based profile for âRecieved Text Anyâ
- Create a task for this profile called âCatBot Singleâ
- This task will include these actions:
- HTTP Post
- Server:Port:
{Your heroku app's domain name}
- Path:
/catbot/message?query=%SMSRB&number=%SMSRF&name=%SMSRN
- Content Type:
text/plain
- Server:Port:
- JavaScriptlet
- Code:
var data = JSON.parse(global('HTTPD')); var response = data.response.text; var delay = data.delay; var number = data.number; setGlobal('DELAY', delay); setGlobal('CATBOTRESPONSE', response); setGlobal('CATBOTRESPONSENUMBER', number);
- Code:
- Wait
- Seconds (Click the âshuffleâ icon to enter a value):
%DELAY
- Seconds (Click the âshuffleâ icon to enter a value):
- Send SMS
- Number:
%CATBOTRESPONSENUMBER
- Message:
%CATBOTRESPONSE
- Number:
- HTTP Post
- Click the back button and exit the app to save changes
- To test if Tasker is working, open the âCatBot Manyâ task and click the green arrow to run it. Cat Facts should be sent to all the recipients that are saved in your database
- Modify Android sms sending limit
- Android will block tasker from sending too many messages at once. You will need to use the Android Debug Bridge (ADB) tool from the Android Platform SDK to fix this
- Go to the Android Developers website and download the SDK tools
- Once the tools have been installed, head to the
platform-tools
directory on your machine where the adb application is located - Open the command line in this directory and run this command
adb shell settings put global sms_outgoing_check_max_count 1000000000
- The SMS outgoing limit is now increased to 1000000000 messages at once, that ought to cover it
Thatâs it!
And in those few easy steps (lolwut), you should have a clone of the Cat Facts codebase and you can now make any changes that your heart desires.