Question

Dynamic Canvas Kit

  • 24 August 2022
  • 1 reply
  • 128 views

Hello There,

Consider me new to the intercome and don't have an idea about even the basics of integration.

 

I'm presenting the use case and seeking a solution for it.

 

Once the user opens up the messenger, he will be shown up with a form that is generated through my server (it is not the same every time. It is based on some conditions). The form content is different for different users based on the logic on the server.

The user clicks on a button on this form and the response is sent back to the server for some business decisions.

 

So I'm confused with following things

  1. How should my server be intimated when the user opens up a messenger (with the user detail)
  2. How can I send the UI back in form of JSON
  3. How can I record the response back if a button in that UI is pressed

 

The information available is in bits and pieces and I'm not able to find the end to end example.

Looking forward for an end to end example do acheive the use case.

 

Regards,


1 reply

Userlevel 2

Hey @tausif​! Daniel from Customer Support Engineering here 🔧 

 

How should my server be initiated when the user opens up the Messenger?

You can configure your Canvas Kit to call your server in the "initialize" request (i.e., the request that's triggered as soon as the app loads).

 

How can I send the UI back in form of JSON?

UI is rendered in Canvas Kit apps as a canvas object. The content object dictates what is displayed on the UI.

 

How can I record the response when a button in that UI is pressed?

You'll want to set up your button to trigger the "submit" action. This way, the "submit" request is triggered every time the button is pressed. Let's call this button "first_button". You'll need to implement a check to see if the button that was clicked is "first_button", and then execute the appropriate action. This is because all buttons will share the same "submit" action, so you'll need to check which of the buttons was pressed. This will look something like:

if (request.body.component_id == "first_button"){ // code goes here }

The request.body will return all of the info that you need when the button is pressed. What you choose to do in the following code block is up to you!

 

Hope this helps 👋 Please feel free to contact us via our Messenger if you are experiencing trouble with Canvas Kit 😊

Reply