mattermost-developer-documentation
mattermost-developer-documentation copied to clipboard
Request for Documentation: App Framework - Document how to set up webhooks
Mattermost user michael.kochell
from https://community.mattermost.com has requested the following be documented:
@shannon.rosas Here is some info on creating webhooks using the App framework
To have your App support webhooks with an external system, set the `remote_webhook_auth_type` field in the manifest to the value "secret". This way, the App framework knows that you want to use a webhook secret. The App framework will generate the secret for you.
When declaring the `call` for a command that will create a webhook in an external system, make sure you `expand` the `app` by providing an `expand` like so: `{app: 'all'}`. Then when this command is run, the App framework will provide the webhook secret in the `context` at `context.app.webhook_secret`.
[mattermost/mattermost-app-zendesk/src/restapi/fTarget.ts](https://github.com/mattermost/mattermost-app-zendesk/blob/136977ded391150bc3db4b25a3d0be9bcabfd858/src/restapi/fTarget.ts#L90)
```ts
}
function getTargetUrl(context: CtxExpandedBotAppActingUserOauth2AppOauth2User): string {
const whSecret = context.app.webhook_secret;
const pluginName = getManifest().app_id;
const whPath = Routes.App.SubscribeIncomingWebhookPath;
let url = context.mattermost_site_url;
Then you can setup your webhook URL in the external system (Trello) as (site url)/plugins/com.mattermost.apps/(app id)/webhook/(arbitrary suffix you provide)?secret=(secret)
When an http request hits this endpoint, the App framework will check the secret for you, and reject the request if the secret coming from the external system is incorrect. You can access the payload coming from the external system in the data
field of the incoming request.
See the original post [here](https://community.mattermost.com/_redirect/pl/aw3fn8hnyfbt8bzz9fs14msxrw).
_This issue was generated from [Mattermost](https://mattermost.com) using the [Doc Up](https://github.com/jwilander/mattermost-plugin-docup) plugin._
This information is being documented by: https://community.mattermost.com/boards/team/rcgiyftm7jyrxnma1osd8zswby/bbft5ccthufy1fcgdrz8ory7bga/vcfirybf6dtbu5b833e4dkhxt5a/ccjnmyp6ixidzmbmm3h66wgy8ae