Integrations WebHooks
Ministry.Chat supports WebHooks to integrate tools and services you like into the platform. WebHooks are simple event-notifications via HTTP POST. This way any application implementing a WebHook is able to POST a message to a Ministry.Chat instance and much more.
With Scripts you can point any WebHook to Ministry.Chat and process the request to print customized messages, define the username and avatar of the user of the message and change the channel where the message will be posted or you can cancel the request to prevent undesired messages.
Available integrations:
Incoming WebHook → Let an external service send a request to Ministry.Chat to be processed.
Outgoing WebHook → Let Ministry.Chat trigger and optionally send a request to an external service and process the response.
By default the WebHooks is designed to post a message only. The message is part of a JSON structure, which has the same format as described in the API documentation on how to “Post a chat message”.
If you would like more power and control over various features of Ministry.Chat, aside from sending and receiving messages, take a look at Ministry.Chat Apps.
Incoming WebHook Script
WebHooks can be handled by ES2015 / ECMAScript 6 scripts to process the request, to print a customized messages or cancel the request to prevent undesired messages.
Create a new Incoming WebHook
Go to your Admin Panel
Go to Integrations
Create a New Integration and select Incoming WebHook
Select the channel where you prefer to receive the alerts; it is possible to override in messages.
Set Script Enabled to
true
Paste your script inside the Script field
Save the integration
Use the generated WebHook URL to POST messages to Ministry.Chat
Script Details
The script should be in ES2015 / ECMAScript 6.
The script expects a global class called Script
. This class is instantiated once, only on the first execution, and kept in memory.
The class has a method called process_incoming_request
, your server calls this method every time is receives a new request. It is called with an Object as a parameter with the request
property.
The process_incoming_request
method returns an object with a content
property that contains valid Ministry.Chat message, or an object with an error
property that returns as the response to the request in JSON format and Code 400 status.
A valid Ministry.Chat message can contain a text
field that is the body of the message. When you redirect the message to a channel other than the one indicated by the Webhook token, you can specify a channel
field, which accepts room id or, if prefixed with "#" or "@", channel name or user.
You can use the console
methods to log information to help debug your script. Find more information about the console here. To view the logs, go to Administration > View Logs
.
Outgoing WebHook Script
Use Scripts to process all messages from a channel, and change how Ministry.Chat makes or cancels the request. You can cancel the request and return a message, or just do nothing. Also, you can make another request inside the script by using the HTTP global helper.
The response of the request also executes the script, calling another method so you can process the response, just like in Incoming WebHooks
Create a new Outgoing WebHook
Go to your Admin Panel
Go to Integrations
Create a New Integration and select Outgoing WebHook
Select the channel where you prefer to use the commands and receive the responses
Enter the URL you want to call in URLs, you can modify this URL inside the script
Set Script Enabled to
true
Paste your script inside the Script field
Save your integration
Script Details
The script should be in ES2015 / ECMAScript 6.
The script expects a global class called Script. This class is instantiated once, only on the first execution, and kept in memory.
The class has a method called prepare_outgoing_request
, this method is called for every message in the configured channel, or it can be filtered by Trigger Words. It is called with an Object as parameter a that contains the request
property.
The prepare_outgoing_request
method returns an object with, at least, url
and method
properties. You can also change the request object, and return it. It is possible even to return nothing and cancel the request, or return a message.
This class has a method named process_outgoing_response
. It is called for every response of the request, with an Object as a parameter that contains the request
property, i.e. the object you returned in the previous method, and a response
property.
The process_outgoing_response
method can return nothing to proceed the default processing, return false
to stop it, or an object with the content
property that contains a valid Ministry.Chat message.
Last updated