Using Web Hook as a channel in Synchronous and Asynchronous Integration modes / How to use and integrate Kore API's

Integration - Synchronous Mode:

  1. Select the channel on Bot builder for your bot

  1. Create an application or select an existing application
  2. Use the client id and client secret to generate the JWT
  3. Select the mode synchronous, copy the webhook URL and save the channel
  4. Approve the channel on admin
  5. Now hit the webhook URL using the incoming request payload as mentioned at the instructions while enabling channel
  6. Below snip shows the response received to webhook URL.

Integration - Asynchronous Mode:

1)Enable the channel on Bot builder for your bot

  1. Create an application or select an existing application
  2. Use the client id and client secret to generate the JWT
  3. Select the mode Asynchronous
  4. Provide the post URL and access token to receive the Asynchronous message

  1. copy the webhook URL and save the channel
  2. Approve the channel on admin
  3. Now hit the webhook URL using the incoming request payload as mentioned at the instructions while enabling channel
  4. The user should receive an empty message with 200 status code for the request made to webhook URL and an asynchronous message is sent to the post URL as shown in below snips

Below is the asynchronous message sent to the post URL. The access token is sent as authorization in the headers.

Below is a sample cURL to use the webhook channel:

curl -X POST
https://bots.kore.ai/chatbot/hooks/st-8d0a0e2a-a107-5384-b08b-42133e2b9371
-H ‘authorization: bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYXBwSWQiOiJjcy0yOGZhODNjMi1hMmY2LTUwZGEtYmU1YS04MjZiMzc4ZGEyNTEifQ.oyY3suCu_p0Hr3b58oOGtHPa7HVG00X5Za5tf9k2cWk’
-H ‘cache-control: no-cache’
-H ‘content-type: application/json’
-H ‘postman-token: 90a15790-0dd1-40b3-e0af-360fe60475d4’
-d '{

“message”: {
“text” : “hi”
},
“from” : {
“id”: “1323465”
},
“to” : {
“id”: “4321”
}
}’

3 Likes

Hi, I’ve successfully set up the webhook and I can now communicate it via postman. I have a question though, can my bot like send me a message in the bot chat window rather than just only a response from the postman?

Hi Subramanyam ,

I have enabled webhook as a channel for my bot. I have followed the steps whichever you have described above. Please find my Curl Command here.

curl -X POST
https://bots.kore.ai/chatbot/hooks/st-128fdf45-788d-5214-90f8-bf3685e01a41
-H ‘Accept: /
-H ‘Authorization: bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYXBwSWQiOiJjcy0yZmMxZDkwNy1lMTFmLTU1YmItOTJkNC01MGY5M2ViYmFmYTQifQ.KWvT1xMoNFRKovGha6E16jYjXpy_kn2hM08HK4ySF3c’
-H ‘Cache-Control: no-cache’
-H ‘Connection: keep-alive’
-H ‘Content-Type: application/json’
-H ‘Host: bots.kore.ai’
-H ‘Postman-Token: b7e57cff-b095-4883-b63d-b20ba2b05b5c,d8a543d8-1125-48cf-b19d-3e69e60bbf40’
-H ‘User-Agent: PostmanRuntime/7.13.0’
-H ‘accept-encoding: gzip, deflate’
-H ‘cache-control: no-cache’
-H ‘content-length: 28’
-d ‘{
“text” : “message”
}’

i have used the client ID to generate the JWT token. however when i hit the URL i am getting invalid access along with 401 unaauthorized code. Could you please assist me on this.

image

Hi @arulvelug,
Please follow the below steps and make a call again to the hook URL:

  1. Publish the bot along with the webhook channel.
  2. Add “from” and “to” to the payload sent in body and hit the URL again.

The user is identified based on the “id” sent under “from” key of payload.

Let me know if you still face the issue.

@Subrahmanyam

I have followed the steps as mentioned ,still facing the same issue (invalid access token). I used synchronous mode . is it mandatory to use " from" and “to” in the body. Please assist.

My requirement is as follows.

  1. Person A creates ticket in service now.
  2. Service now agent now handles the ticket and moves the state from Assigned to Work in Progress.
  3. When he changes the ticket state, The webhook has to receive the data and post the message to PERSON A.

Please let me know if this can be achieved using synchronous or asynchronous mode of integration. If it is asynchronous mode How can we get the ID of from and to?

Screenshots (invalid access token)
Headers

image

Body

image

Regards
Arul

@arulvelug Could you please create a new app, associate the new app with the webhook channel and republish the bot along with the channel?

Yes, ‘from’ and ‘to’ keys are mandatory in the payload.

Regarding your use case, please check if the below configuration could help (Provided, service now offers an endpoint to poll the status of ticket)

  1. Create a web service alert in the bot which notifies the user about the ticket status updates.
  2. In the dialog which is used to raise the service now ticket, configure the web service alert as a smart alert at a service node.
  3. During the runtime, in the dialog wherein service now ticket registration happens, when the service node at which the smart alert is configured is executed, an alert instance is created at the user.
  4. This alert instance polls the service as defined at the alert based on the scheduled frequency and would push alert notifications to the user based on the received response.

Hello, I’m trying to test the syncronus webhook with postman, but always i get “Invalid access” as response, maybe i have problems with the authorization token. I’m using a python script to generate the token. I’m not sure what value I must put on “sub” in the JWT Payload is any random number? also where i must use the secret code?

{
“appId”: “{{clientId of the bot}}”,
"sub" : “{{random number}}” <— ? any random number? as string or int?
}

this is my python script:
import jwt

client_id = 'cs-088a753a-a8fe-58b7-bfbe-ab5801e3b9ea'
random_num =  '12345'

my_token = jwt.encode({
  "appId": client_id,
  "sub" :  random_num
  }, 'secret', algorithm='HS256')

print(my_token)

@laros Could you please check and confirm if the webhook channel has been published? Also, could you please share the cURL so that we could debug further?

The webhook channel is configured but mi bot isn’t published yet the status is in-development". Webhook channel are only available on published bots? I used “cheat developer on” in the bot chat.

thanks for your help :slight_smile:

curl -X POST
https://bots.kore.ai/chatbot/hooks/st-8a35228a-fa72-5c80-b311-37ab234a1497
-H ‘Accept: /
-H ‘Authorization: bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhcHBJZCI6ImNzLTA4OGE3NTNhLWE4ZmUtNThiNy1iZmJlLWFiNTgwMWUzYjllYSIsInN1YiI6IjEyMzQ1In0.ZF5OYUB50LnogdUE1T9sozQJ9dE6IDlKTLF-oZ1v1sM’
-H ‘Cache-Control: no-cache’
-H ‘Connection: keep-alive’
-H ‘Content-Type: application/json’
-H ‘Host: bots.kore.ai’
-H ‘Postman-Token: 324e1e02-0638-4407-9448-c2cf0d80977e,a139e540-979a-4238-93ab-cc94ad42cb46’
-H ‘User-Agent: PostmanRuntime/7.15.0’
-H ‘accept-encoding: gzip, deflate’
-H ‘cache-control: no-cache’
-H ‘content-length: 28’
-d '{
“text” : “Hola”
}

Hi @laros , The payload you are passing to the hook URL seems to be incorrect. You will need to include the from and to IDs in the body.

Please refer to the cURL mentioned here:

@arulvelug The webhook alerts cannot be configured as the webhook instance might change dynamically for a user to the user. Also, in your case, the user should not explicitly configure/invoke the alert. The bot should automatically inform the user in case of ticket status change. Hence, we are suggesting to use smart alerts and there is no other way to avoid polling to the service.

To explain how it dynamically changes for User to User with a scenario where webhook alerts can be configured.

We create an alert task with “Connection Type” as “Webhook” and provide the sample response in the “API request” tab and Finish the alert set up in the platform.

Now, when a user is communicating to the bot and the alert is configured by the user, then a Webhook URL will be exposed to the user in the chat window.

User needs to configure this Webhook URL in the external 3rd parties to get updates whenever changes are made at the 3rd party end.

For example, I as a developer would create a webhook alert when I have a use-case where the end-user would configure(Trigger) the alert in the bot as per his/her need with an external service.
So as mentioned above, when the user configures the alert, they would receive a Webhook URL from the bot.

They need to set this URL in the 3rd party service(like JIRA) to get constant updates from it. (Every service like JIRA, BitBucket, Git, etc have the developer documentation to set up these Webhook URLs with them).

The Webhook URL that is given to the user changes from user to user and instance to instance. You can observe that the webhook URL below is different from the above screenshot.

For your use-case where you would like to send alerts to the user in case of ticket status change, etc, this webhook alert functionality which is currently available will not be suitable.
Hence, we are suggesting to use smart alerts and there is no other way to avoid polling to the service.

Could you please confirm whether webhook channel has to be publish? Will it work if it’s only configured?

@leena8feb
As per current design, web-hook channel(s) needs to be published in order to communicate.

Hi followed the examples step by step and I’m getting “Invalid access Token” always! I need to send the access token anywhere in my post request?

Please copy your cURL here.
Also, please ensure you have signed the jwt token using client secret as defined in the app for webhook channel.

curl --location --request POST ‘https://bots.kore.ai/chatbot/hooks/st-61ef1943-b2ce-52a2-9531-3a48d5c01dad
–header ‘Content-Type: application/json’
–header ‘Authorization: bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhcHBJZCI6ImNzLTQ0NWRkZDk4LWMwNzMtNTQ3Yi1iOGFjLWU1MzQ5MDM3NjA5MSIsInN1YiI6IitHLzJHaGxiT3NRSWxqMnNHY0l3N0RiTDc4aU40dHY3NWpMUVVQV3FhZjA9IiwiYWNjZXNzVG9rZW4iOiJxd2VydHkxMjMiLCJqdGkiOiI4NzI3NDYwMi0xMjY2LTQwZGItYmI0NS04YzJhM2Q2ZGNjZmIiLCJpYXQiOjE1OTUzMzAwMTQsImV4cCI6MTU5NTMzMzYxNH0.EctZ6GpC7mZFpOy7rEHR80W2bay56MxzqowkhYmq6bg’
–data-raw ‘{
“text”: “hi”
}’

@ruben.costa

I see that your JWT has JTI. If that is the case, Platform will not allow same JWT token again.
Only sub and appId in the payload matter anyway.

{
“sub”:"koresupport@kore.com",
“appId”: “cs-e2XXXXXXXXX1-7c94-553b-9d97-66XXXX40a”
}

Use the below in body

{
        "message":{
			"text" : "UTTERANCE"
		},
        "from" :{
            "id": "a@b.com"
		},
        "to" :{
            "id": "st-59d0XXXXXBOT-IDXXXXX04a0cde8a1"

		}
}


Sorry but still missing something.

Let me share all my steps:

  1. Create a JWT token with the follow payload:
    {
    “appId”: “cs-445ddd98-c073-547b-b8ac-e53490376091”,
    “sub” : “+G/2GhlbOsQIlj2sGcIw7DbL78iN4tv75jLQUPWqaf0=”
    }

  2. The integration mode is Synchronous

  3. in the postman, I use the Authorization Bearer Token and past te JWT token:
    eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcHBJZCI6ImNzLTQ0NWRkZDk4LWMwNzMtNTQ3Yi1iOGFjLWU1MzQ5MDM3NjA5MSIsInN1YiI6IitHLzJHaGxiT3NRSWxqMnNHY0l3N0RiTDc4aU40dHY3NWpMUVVQV3FhZjA9In0.NOZkuSp67M3Efu29ka8O-fASQoo3W4Qa9lw9cz3swFM

  4. I’m doing a post to this URL https://bots.kore.ai/chatbot/hooks/st-61ef1943-b2ce-52a2-9531-3a48d5c01dad

  5. the body I’m using what you gave me
    6 ) Result: invalid access token

@ruben.costa
While creating jwt I hope you signed the same with secret key. Please confirm. And if that is also done, please send me the secret in email swagata.sengupta@kore.com to take a look.

The webhook call was working fine ,but from past 2 days the request is getting timed out