The Rocket Chat documentation provides sample scripts for both incoming and outgoing web hooks. This script is run when the web hook is called. After an incoming web hook is created, the Rocket Chat generates a url that can be used by other applications. For example when an application calls the incoming url, Rocket Chat will run the script that we specified when creating the incoming web hook. The script can do some processing and return the result as a message. This message is displayed to the channel users.
After we have created an incoming web hook in Rocket Chat, we have to copy the generated url and use that as a callback url for the Trello web hook. So each time a Trello object is updated, the Rocket Chat url is called automatically. When this url is called, the script associated with the url is run on the Rocket Chat server and the result is displayed to the end user. The Trello web hook passes parameters to the callback url so the script for the incoming web hook can use the parameters. e.g for displaying the name of the Trello card to the user. The incoming web hook basically displays information from an external application to the channel users.
When we create an outgoing web hook, we have to give one or more urls that should be called when the web hook is fired. The outgoing web hook is fired by Rocket Chat when the user enters certain terms. For example a command for listing all Trello cards in a certain list. When the user enters the command, the script associated with the outgoing web hook is called. This script can access the urls associated with the outgoing web hook. Depending on the user choice, the outgoing web hook can be fired each time the user enters a message or when a certain text appears in the message. The script given in the outgoing web hook is specified as a class with two functions. One is called prepare_outgoing_request and is called each time the user enters text. The second one is called process_outgoing_response and is called when the url given in the outgoing web hook is called. The process_outgoing_response function gets the response from the url. When the first function prepare_outgoing_request is called, it can either call the url associated with the web hook or it can display help information to the user. For example on how to use the command.
I created a project on Bit Bucket called Rocket Chat Trello Integration. It contains the incoming and outgoing scripts for Rocket Chat web hooks and also a script for creating Trello web hooks. The script for creating Trello web hooks basically creates a web hook for each card in a given set of Trello Lists. The following screenshot describe how the integration works:
When the user types trello help, the command description is shown to the user. When the user enters the correct command, the response from Trello is shown. In this example the list of all Trello cards in the list Doing is shown