Giter VIP home page Giter VIP logo

hookbuster's Introduction

hookbuster

Description

This application demonstrates how to register for Webex Teams message, membership and rooms events via websocket using the Webex Javascript SDK. Currently (as of September, 2019), the Webex JS SDK is the only way to receive Webex events via websocket. This app is a simple node.js app that registers for events in Webex Teams via websocket, and forwards them to a localhost port for bots or apps that are listening on that port. It is particularly useful for Webex Teams applications written in a language other than javascript that need to run behind a firewall, and cannot register for webhooks since they do not have a public IP address.

Requirements

  • Webex Teams access token: this will be used by the hookbuster to create websocket listeners. Ideally you would use the access token that is used by the application that hookbuster will forward the events to.
  • open port on TARGET: this is where the incoming HTTP requests will be forwarded to, so that the listening app can process them
  • node.js: will be used to run the app locally
  • npm: will be used to install dependencies

Install and run

  • clone the repo
  • npm install
  • node app.js

Usage -- demonstration mode

By default the app will run in "demonstration mode" with a command line interface that solicits the access token, port, and which resources and events to register for:

  ,----------------------------------------------------------.
  |                                                          |
  |    _   _             _    _               _              |
  |   | | | | ___   ___ | | _| |__  _   _ ___| |_ ___ _ __   |
  |   | |_| |/ _ \ / _ \| |/ / '_ \| | | / __| __/ _ \ '__|  |
  |   |  _  | (_) | (_) |   <| |_) | |_| \__ \ ||  __/ |     |
  |   |_| |_|\___/ \___/|_|\_\_.__/ \__,_|___/\__\___|_|     |
  |                                                          |
  |                                                          |
  `----------------------------------------------------------'

? Enter your access token > AaBbCcDdEeFfGgHhIiJjAaBbCcDdEeFfGgHhIiJjAaBbCcDdEeFfGgHhIiJj_ABCD_1a2b3c4d-1234-abcd-9876-abcdefghijkl
! AaBbCcDdEeFfGgHhIiJjAaBbCcDdEeFfGgHhIiJjAaBbCcDdEeFfGgHhIiJj_ABCD_1a2b3c4d-1234-abcd-9876-abcdefghijkl
INFO: token authenticated as Bot
? Enter a port you will forward messages to > 5000
! 5000
? Select resource [ a - all, r - rooms, m - messages, mm - memberships, aa - attachmentActions ] > a
INFO: Listening for events from the rooms resource
INFO: Registered handler to forward  rooms:created events
INFO: Registered handler to forward  rooms:updated events
INFO: Listening for events from the messages resource
INFO: Registered handler to forward  messages:created events
INFO: Registered handler to forward  messages:deleted events
INFO: Listening for events from the memberships resource
INFO: Registered handler to forward  memberships:created events
INFO: Registered handler to forward  memberships:updated events
INFO: Registered handler to forward  memberships:deleted events
INFO: Listening for events from the attachmentActions resource
INFO: Registered handler to forward  attachmentActions:created events

Tip: you can use the javabot to test how this app works. Start javabot with your access token and enter a localhost port, where javabot will listen to incoming messages. While both apps are running, open a Webex Teams space with the bot, whose access token you used and say hello. It should greet you back. ๐Ÿ‘‹

Usage -- deployment mode

If the following environment variables are set:

  • TOKEN
  • TARGET
  • PORT

hookbuster will automatically register for all of the webhook firehose events, using the TOKEN and then forward any received events to TARGET:PORT. If you only set PORT and TOKEN in your environmental variables, then TARGET will be defaulted to localhost. Otherwise (if you do not use environmental variables) you will be prompted to enter a target manually.

Dependencies

"dependencies": {
  "asciiart-logo": "^0.2.6",
  "chalk": "^2.4.2",
  "clear": "^0.1.0",
  "webex": "^1.80.154"
}

A note about "read receipts"

In addition to adding support for Webex Teams events via websocket, the Webex JSSDK also introduces a new memberships:seen event which effectively notifies an application when a member of a space has seen messages posted in that space. As of September, 2019, there is not yet a corresponding webhook, and consequently this event is not one that is delivered via the webhook firehose. Since this app is designed primarily as a way to get webhook events to applications running behind a firewall, by default it does NOT register for membership:seen events.

If you would like to add membership:seen (read receipt) event processing to your application, simply uncomment the seen element in the object.memberships object defined near the top of cli.js

For more information on how the membership:seen events behave, run the events via socket JSSDK sample. It is worth noting that the system generally generates MANY more membership:seen events than all the rest of the Webex Teams events, so register for these only if your app is able to make use of them.

hookbuster's People

Contributors

adamweeks avatar ashjorda avatar bbender avatar jbenyovs avatar jpjpjp avatar legion49f avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hookbuster's Issues

Maximum call stack size exceeded

I have built hookbuster into a containerized application and have had the container crash with this trace back a few times.

failed to execute Logger#warn RangeError: Maximum call stack size exceeded
hookbuster_1 | at walkAndFilter (/node_modules/@webex/plugin-logger/dist/logger.js:92:23)
hookbuster_1 | at walkAndFilter (/node_modules/@webex/plugin-logger/dist/logger.js:122:23)

Any help will be appreciated. I am not a JS developer unfortunately but i have some inclination that this might be due to a recursion loop.

Thanks in advance!

Truncated messages

Hi team, I have noticed that when using hookbuster if a webhook being received with a payload more than 1 MB the internal HTTP POST would have the JSON content as truncated which is triggering an exception in backend code, so is this a known issue ? this is happening mostly when my BOT is sending messages into some space the webhook comes for the BIT messages.

Issues in Listening for Events

I have cloned and followed the same steps, looks like I am having an issue when running in two different machines.|

Not working machine logs
LoggerProxy->warn#NO LOGGER DEFINED
INFO: token authenticated as sushi

Working machine logs
LoggerProxy->warn#NO LOGGER DEFINED
INFO: token authenticated as sushi
INFO: Listening for events from the rooms resource
INFO: Registered handler to forward rooms:created events
INFO: Registered handler to forward rooms:updated events
INFO: Listening for events from the messages resource
INFO: Registered handler to forward messages:created events
INFO: Registered handler to forward messages:deleted events
INFO: Listening for events from the memberships resource
INFO: Registered handler to forward memberships:created events
INFO: Registered handler to forward memberships:updated events
INFO: Registered handler to forward memberships:deleted events
INFO: Listening for events from the attachmentActions resource
INFO: Registered handler to forward attachmentActions:created events

Incorrect Content-Length header on POST request with messages containing emoji's or other double-width unicode characters

If hookbuster processes a message containing an Emoji or other double-width unicode characters (emdash, smart quotes, etc) then the Content-Length Header on the generated POST request is smaller than the payload, resulting in truncated json in many web servers.

For example a message containing a single emoji is processed by hookbuster:

INFO: messages:created received
INFO: event forwarded to localhost:8000
INFO: {"createdBy":"<redacted>","orgId":"<redacted>","resource":"messages","ownedBy":"creator","status":"active","created":"2022-06-22T20:05:09.053Z","data":{"id":"<redacted>","roomId":"<redacted>","roomType":"direct","text":"๐Ÿ™„","personId":"<redacted>","personEmail":"<redacted>","html":"<h1>๐Ÿ™„</h1>","created":"2022-06-22T20:05:31.499Z"},"event":"created","actorId":"<redacted>gtYWVkYi1kMjgzZWM1NGY2Mjc"}
statusCode: 200

The web server receives the request, but the body is truncated so that the ending jc"} is missing. I took a packet capture and confirmed that the remaining payload is present in the request, but beyond the 802 bytes set by the content length header.

INFO:root:Starting httpd...

INFO:root:POST request,
Path: /
Headers:
Content-Type: application/json
Content-Length: 802
Host: localhost:8000
Connection: close



Body:
{"createdBy":"<redacted>","orgId":"<redacted>","resource":"messages","ownedBy":"creator","status":"active","created":"2022-06-22T20:05:09.053Z","data":{"id":"<redacted>","roomId":"<redacted>","roomType":"direct","text":"๐Ÿ™„","personId":"<redacted>","personEmail":"<redacted>","html":"<h1>๐Ÿ™„</h1>","created":"2022-06-22T20:05:31.499Z"},"event":"created","actorId":"<redacted>TRlNTgtYWVkYi1kMjgzZWM1NGY2M

127.0.0.1 - - [22/Jun/2022 15:05:35] "POST / HTTP/1.1" 200 -

This discussion on Stack Overflow seems relevant to the issue: https://stackoverflow.com/questions/54369513/how-to-count-the-correct-length-of-a-string-with-emojis-in-javascript

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.