Getting Started

Hooks

Advanced

Miscellaneous

REST API Hooks

REST API endpoint based hook

REST API based hooks gives JAWCE powers to connect to any other system or backend of your choice.

One strict rule will be that, your endpoints must be a POST request which accepts a HookArgsRest model as explained before.

To link a REST API hook, prefix it with rest:<your-http(s)-endpoint> as below

1000:
  type: text
  on-receive: "rest:https://example.com/api/notify"
  message: "Type `yes` to receive a Slack notification from us"
  routes:
    "yes": "next-stage"

An example endpoint implementation will be as below (Python Example)

# ...
# using FAST API

@app.post("/notify")
def slack_notify(args: HookArgsRest):
    print("Received args: {}".format(args))

    # assume user once provided their slack email before
    # & is stored in session as a prop
    slack_id = get_slack_id_from_props(session_id=args.channelUser.waId)

    # check if user answered yes
    if args.userInput.lower() == "yes":
        send_slack_notification(id=slack_id)

    return args

Endpoint Security

You must be wondering, what if my endpoint has API-KEYs or some sort of security. The engine has an internal session key: SessionConstants.HOOK_USER_SESSION_ACCESS_TOKEN

If your bot has login functionality, you can save the secret key in a session under this key and the engine will check this and add as Authorization header when calling your endpoint

By default, the engine assume, access token is a Bearer auth token