-
Notifications
You must be signed in to change notification settings - Fork 4
Scratch from Hubot project
MichaelYuxiang edited this page Oct 19, 2016
·
1 revision
Cha project is to format message for ChatOpt endpoints,
Prerequisite: Node.js and npm Hubot and yeoman
-
Generate Hubot project :
yo hubot Input: [Owner],[Bot name],[Description], [Bot adapter], then get your hubot projec ready. For more detai: https://github.com/HPSoftware/cha/wiki -
Get Cha from git-hub
npm install --save git+https://github.com/HPSoftware/cha.git -
Set token for ChatOps:
For example: set HUBOT_SLACK_TOKEN=xoxb-???????????-???????????????? -
Create scripts for your bot
https://github.hpe.com/IncubationLab/cha/wiki -
Initial Cha in Hubot project
Init Cha.Api Cha = require 'cha' module.exports = (robot) -> Cha.Api.initHubot robot robot.Cha = Cha Init Cha.Frameworkor
Init Cha.Framework Cha = require 'cha' module.exports = (robot) -> Cha.Framework.initHubot robot path = require("path").join __dirname, "./cha-tpls.yaml" Cha.Framework.init(path, robot.adapterName) robot.Cha = Cha -
Prepare Template and internationalization
Template: link
I18N: link
-
Send message with Cha.Api API: link Example:
robot.hear /ta$/i, (res)-> msg = text: "This is text with list" parts:[ title: "This is title 1" text: "This is part title 1" color: "good", fields:[ { "title": "field 1", "value": "value 1" }, { "title": "field 2", "value": "value 2" }, { "title": "field 3", "value": "value 3" } ] , title: "This is title 2" title_link: "http://example.com" text: "This is part title 2" color: "warn", actions:[ name: "ok" text: "OK" , name: "cancel" text: "Cancel" ] ] msg = new robot.Cha.Api.Message(msg) robot.send msg -
Send message with Cha.Template
Template: See link
Example:
robot.hear /tf$/i, (response)-> msg = name: "kick_off_warroom" # type: "text" model: title: "Digital banking slow" id: "IM1293" users: ['a','b','c'] description: "Digital banking is very slow, timeout" severity: "high" submitter: "James, T, Cook" affectedService: id: "CI192283", name: "digital-banking" "@url": "/api/urest/r/incident/IM1293" text: "This is part title 1" color: "good" parts:[ { fields:[ { "title": "field 1", "value": "value 1" }, { "title": "field 2", "value": "value 2" } ] } ] content = new robot.Cha.Framework.Message msg.name, msg.model #, msg.type response.reply content