How to use hubot - 10 common examples

To help you get started, we’ve selected a few hubot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mtsmfm / hubot-test-helper / src / index.js View on Github external
if (roomName == this.adapter.name) {
      this.adapter.messages.push(['hubot', str]);
    } else {
      if (!(roomName in this.messagesTo)) {
        this.messagesTo[roomName] = [];
      }
      this.messagesTo[roomName].push(['hubot', str]);
    }
  }

  loadAdapter() {
    this.adapter = new Room(this);
  }
}

class Room extends Hubot.Adapter {
  // XXX: https://github.com/hubotio/hubot/pull/1390
  static messages(obj) {
    if (obj instanceof MockRobot) {
      return obj.adapter.messages;
    } else {
      return obj.messages;
    }
  }

  constructor(robot) {
    super();
    this.robot = robot;
    this.messages = [];

    this.privateMessages = {};
github mtsmfm / hubot-test-helper / src / index.js View on Github external
'use strict'

const Fs    = require('fs');
const Path  = require('path');
const Hubot = require('hubot/es2015');

process.setMaxListeners(0);

class MockResponse extends Hubot.Response {
  sendPrivate(/* ...strings*/) {
    const strings = [].slice.call(arguments, 0);

    this.robot.adapter.sendPrivate.apply(this.robot.adapter, [this.envelope].concat(strings));
  }
}

class MockRobot extends Hubot.Robot {
  constructor(httpd) {
    if (httpd == null) { httpd = true; }
    super(null, null, httpd, 'hubot');

    this.messagesTo = {};

    this.Response = MockResponse;
  }
github mtsmfm / hubot-test-helper / src / index.js View on Github external
const Fs    = require('fs');
const Path  = require('path');
const Hubot = require('hubot/es2015');

process.setMaxListeners(0);

class MockResponse extends Hubot.Response {
  sendPrivate(/* ...strings*/) {
    const strings = [].slice.call(arguments, 0);

    this.robot.adapter.sendPrivate.apply(this.robot.adapter, [this.envelope].concat(strings));
  }
}

class MockRobot extends Hubot.Robot {
  constructor(httpd) {
    if (httpd == null) { httpd = true; }
    super(null, null, httpd, 'hubot');

    this.messagesTo = {};

    this.Response = MockResponse;
  }

  messageRoom(roomName, str) {
    if (roomName == this.adapter.name) {
      this.adapter.messages.push(['hubot', str]);
    } else {
      if (!(roomName in this.messagesTo)) {
        this.messagesTo[roomName] = [];
      }
github loafoe / hubot-matteruser / src / matteruser.js View on Github external
if (msg.data.channel_type === 'D') {
        if (!new RegExp(`^@?${this.robot.name}`, 'i').test(text)) { // Direct message
          text = `${this.robot.name} ${text}`;
        }
        if (!user.mm) { user.mm = {}; }
        user.mm.dm_channel_id = mmPost.channel_id;
    }
    this.robot.logger.debug(`Text: ${text}`);

    if (mmPost.file_ids) {
        this.receive(new AttachmentMessage(user, text, mmPost.file_ids, mmPost.id));
    // If there are interesting props, then include them for bot handlers.
    } else if ( mmPost.props ? mmPost.props.attachments : undefined ) {
        this.receive(new TextAndPropsMessage(user, text, mmPost.props, mmPost.id));
    } else {
        this.receive(new TextMessage(user, text, mmPost.id));
    }
    this.robot.logger.debug("Message sent to hubot brain.");
    return true;
}
github saraford / atom-hubot / lib / hubot.js View on Github external
toggle() {
    console.log('Hubot was toggled again!');
    var isVisible = this.modalPanel.isVisible();

    if (isVisible) {
      this.modalPanel.hide();

    } else {
      this.modalPanel.show();

      try {

          robot = Hubot.loadBot(undefined, "electron", false, "Hubot", false);

          var stream = fs.createWriteStream(__dirname + '/../logs/hubot.log');
          robot.logger = new Log('debug', stream);

          robot.adapter.wireUpResponses(updateWindowWithHubotMessage);
          user = robot.brain.userForId(1, 'atom', 'Shell');
          console.log('hubot loaded');

          // wire up the buttons
          hubotOutputWindow = $('#hubot-output');
          scriptsPathLink = $('#scripts-link');

          // setup the watcher on the play.coffee
          startWatchingUserScript();

          reloadAllScripts();
github hubotio / hubot-mock-adapter / index.js View on Github external
'use strict';

const Adapter = require('hubot/es2015').Adapter;

class MockAdapter extends Adapter {
  send (envelope/* , ...strings */) {
    const strings = [].slice.call(arguments, 1);
    this.emit('send', envelope, strings);
  }
  reply (envelope/* , ...strings */) {
    const strings = [].slice.call(arguments, 1);
    this.emit('reply', envelope, strings);
  }
  topic (envelope/* , ...strings */) {
    const strings = [].slice.call(arguments, 1);
    this.emit('topic', envelope, strings);
  }
  play (envelope/* , ...strings */) {
    const strings = [].slice.call(arguments, 1);
github loveonelong / hubot-telegram-better / src / telegram.js View on Github external
this.receive(new TextMessage(user, text, message.message_id))
      // Callback query
    } else if (message.data) {
      text = this.cleanMessageText(message.data, message.message.chat.id)

      this.robot.logger.debug(`Received callback query: ${message.from.username} said '${text}'`)

      user = this.createUser(message.from, message.message.chat)

      this.api.invoke('answerCallbackQuery', { callback_query_id: message.id }, function (err, result) {
        if (err) {
          this.robot.logger.error(err)
        }
      })

      this.receive(new TextMessage(user, text, message.message.message_id))

      // Join event
    } else if (message.new_chat_member) {
      user = this.createUser(message.new_chat_member, message.chat)
      this.robot.logger.info(`User ${user.id} joined chat ${message.chat.id}`)
      this.receive(new EnterMessage(user, null, message.message_id))

      // Exit event
    } else if (message.left_chat_member) {
      user = this.createUser(message.left_chat_member, message.chat)
      this.robot.logger.info(`User ${user.id} left chat ${message.chat.id}`)
      this.receive(new LeaveMessage(user, null, message.message_id))

      // Chat topic event
    } else if (message.new_chat_title) {
      user = this.createUser(message.from, message.chat)
github loveonelong / hubot-telegram-better / src / telegram.js View on Github external
if (message.chat.type === 'group') groupsManager.update(message.chat.id, { name: message.chat.title })

    if (this.robot.brain.get(`handled${message.message_id}`) === true) {
      this.robot.logger.warning(`Message ${message.message_id} already handled.`)
      return
    }
    this.robot.brain.set(`handled${message.message_id}`, true)

    // Text event
    if (message.text) {
      text = this.cleanMessageText(message.text, message.chat.id)
      this.robot.logger.info(`Received message: ${message.from.first_name} ${message.from.last_name} said '${text}'`)

      user = this.createUser(message.from, message.chat)
      this.receive(new TextMessage(user, text, message.message_id))
      // Callback query
    } else if (message.data) {
      text = this.cleanMessageText(message.data, message.message.chat.id)

      this.robot.logger.debug(`Received callback query: ${message.from.username} said '${text}'`)

      user = this.createUser(message.from, message.message.chat)

      this.api.invoke('answerCallbackQuery', { callback_query_id: message.id }, function (err, result) {
        if (err) {
          this.robot.logger.error(err)
        }
      })

      this.receive(new TextMessage(user, text, message.message.message_id))
github saraford / train-your-hubot / renderer.js View on Github external
function startHubot() {
  // adapterPath, adapterName, enableHttpd, botName, botAlias
  // adapterPath - the first parameter it is never used, hence undefined
  //debugger
  robot = Hubot.loadBot(undefined, "electron", false, "Hubot", false);
  robot.adapter.once('connected', loadInitialScripts);
  robot.adapter.wireUpResponses(updateWindowWithHubotMessage);
  robot.run();

  updateWindowWithHubotMessage("I'm ready!");
}
github loafoe / hubot-matteruser / src / matteruser.js View on Github external
userAdded(msg) {
    // update channels when this bot is added to a new channel
    if (msg.data.user_id === this.self.id) {
      this.client.loadChannels();
  }
    try {
      const mmUser = this.client.getUserByID(msg.data.user_id);
      this.userChange(mmUser);
      const user = this.robot.brain.userForId(mmUser.id);
      user.room = msg.broadcast.channel_id;
      this.receive(new EnterMessage(user));
      return true;
    } catch (error) {
      return false;
  }
}