Skip to content

rocket.chat incoming webhook parser script example

Christoph Bajohr edited this page Nov 29, 2016 · 3 revisions
class Script {
  process_incoming_request({ request }) {
    var content = request.content;

    var message_icon = ":chipmunk:";
    var attachments = [{}];
    var text = '';
    var username = 'Rocket Chat Notifier';

    if(content.event){
      username = content.event;
    }

    if(content.emoji){
      message_icon = content.emoji;
    }

    if(content.attachment)
    {
      for(var key in content.attachment){
        attachments[0][key] = content.attachment[key];
      }
    }

    text = content.message;

    // DEBUG
    // debug = "\n\n\n DEBUG:\n\n Request: "+content.action+" \n\n content: ```JSON\n"+JSON.stringify(content)+"```"
    // text += debug;

    // background debug
    console.log(content);

    return {
      content: {
        username: username,
        icon_emoji: message_icon,
        text: text,
        attachments: attachments
      }
    };
  }
}
Clone this wiki locally