Setting up specific bots
Individual bots can be set up manually by the process described below:
- Clone our OnBot repository from github (git clone https://github.com/CognizantOneDevOps/OnBot.git)
- Copy the desired bot scripts from the scripts folder of the cloned repo
- Run this command: npm install -g yo generator-hubot
- Create a parent folder myhubot
- Run the following commands:
cd myhubot
yo hubot
- Copy the scripts from the cloned repository (first step) into myhubot/scripts folder
yo generator creates the package.json file under myhubot directory
Download the workflow_botname.json attached with the respective bots below, then rename it as workflow.json and place into the myhubot directory
- Run: npm install
- Now set the required environment variables (As mentioned below in Environment Variables for specific bots section and also refer section Environment variables common for all bots for additional common env variables)
- Slack: npm install hubot-slack Microsoft Teams: npm install hubot-botframewok
Finally, start the bot as a background process (logs will be redirected to hubot.log file): Slack: nohup ./bin/hubot -a slack > hubot.log &
Microsoft Teams: nohup ./bin/hubot -a botframework > hubot.log &
Before starting the bot, Run npm install hubot-<adapter> to install specific node module for the adapter (chat application) you want to use.
At any time the bot running in background can be stopped by this command: ps aux | grep -ie <botname> | awk '{print $2}' | xargs kill -9
The <botname> can be fetched from the following line of the bin/hubot file:
exec node_modules/.bin/hubot --name "botname" "$@"
EXPRESS_PORT (Port number where the hubot will run)
MY_POD_IP (Host address where bot is running)
MONITOR_INTERVAL (Time Interval for monitoring bot)
MONITOR_RETENSION (mapped to 1 (stores a jsonobj in elasticsearch which has all hubot metrics of a current second))
MONGO_DB_URL (mongodb database name for approval process of bot actions)
MONGO_COLL (mongodb collection name for approval process of bot actions)
MONGO_COUNTER (mongodb collection name for storing the number of next ticket to be generated)
MONGO_TICKETIDGEN (stores the Id of the collection referred by MONGO_COUNTER)
APPROVAL_APP_URL (middleware application endpoint which will handle approval flow in mattermost)
MONGO_DB_NAME (The database name which has MONGO_COLL and MONGO_COUNTER in it)
Slack: HUBOT_SLACK_TOKEN (API token for connecting with slack)
Mattermost
MATTERMOST_ENDPOINT (context of the endpoint where bot is running with mattermost adapter)
MATTERMOST_INCOME_URL (Mattermost Incoming webhook)
MATTERMOST_TOKEN (Mattermost outgoing token - to be configured with outgoing webhook)
Microsoft Teams
BOTBUILDER_APP_ID (App Id of your bot)
BOTBUILDER_APP_PASSWORD (secret password for your bot)
BOTBUILDER_ENDPOINT (Sets a custom HTTP endpoint for your bot to receive messages on (default is /api/messages). For Example: /master , /github , /jira , /jenkins , /sendtobot)
CURRENT_CHANNEL (MS Teams current channel incoming webhook url. Reference: https://docs.microsoft.com/en-us/outlook/actionable-messages/send-via-connectors)
ADMIN_CHANNEL (MS Teams admin channel incoming webhook url for approval workflow. Reference: https://docs.microsoft.com/en-us/outlook/actionable-messages/send-via-connectors)
To implement the approval flow with the bot, whichever collection name you put in MONGO_COUNTER variable(mentioned above) should be present inside the db set by MONGO_DB_NAME.
For example- suppose you have MONGO_COUNTER=counters and MONGO_DB_NAME=hubot set in your environment. Then you should have a database called "hubot" inside your mongodb. This "hubot" should contain a collection named "counters" having this structure: { _id: "ticketIdGenerator",seq: 100}
To create a collection like this, go to your mongo shell and execute below steps:
- use hubot
- db.createCollection("counters")
- db.counters.insert({_id: "ticketIdGenerator",seq: 100})
The MONGO_TICKETIDGEN should contain the Id of the collection referred by MONGO_COUNTER. Therefore, for the above example, MONGO_TICKETIDGEN=ticketIdGenerator.
Reload command setting
Hubot has a built in command which allows any changes made in the coffeeScripts to take effect without restarting the bot. This is ideal for developers who want to customize the scripts according to their unique needs. To use this command, open the hubot-scripts.json file inside your bot folder(myhubot) and write the following:
["reload.coffee"]
Save this and run your bot as usual. Thereafter if you make any changes in coffeeScripts, simply run the "reload all scripts" command. This will take the in latest changes without interrupting the running bot.