notify-zulip/index.js

38 lines
955 B
JavaScript

const { getInput} = require("@actions/core")
const { existsSync, readFileSync } = require("fs")
const zulipInit = require("zulip-js");
// Pass the path to your zuliprc file here.
const config = {
username: getInput("bot.email"),
apiKey: getInput("bot.key"),
realm: getInput("url")
};
(async () => {
const client = await zulipInit(config);
let content = getInput("content.text");
if(getInput("content.type")=="file"){
const path = getInput("content.path")
if(!existsSync(path)){
throw new Error("I/O: can't find "+path)
}
if(content&&content.trim().length){
content += "\r\n\n";
}
content += readFileSync(path).toString()
}
// Send a stream message
let params = {
to: getInput("stream"),
type: "stream",
topic: getInput("topic"),
content,
};
console.log(await client.messages.send(params));
})();