Live Helper Chat support forum.. Forum is locked. New place for questions - Github Discussions

You are not logged in.

Announcement

#1 2020-07-03 21:16:05

rogeriomayer
Member
Registered: 2020-07-03
Posts: 12

Show json array on buttons in a boot

Como posso mostrar a resposta de um rest api que retorna um array em vários botões?
Ex:
Minha REST API resposta:
{
types: [
            {typeName:Button1},
            {typeName:Button2},
            {typeName:Button1}
            ]
}

Chat

Olá escolha uma opção!
[Button1]    [Button2]   [Button3]

Offline

#2 2020-07-04 04:17:45

remdex
Administrator
From: Lithuania
Registered: 2012-09-23
Posts: 3,661
Website

Re: Show json array on buttons in a boot

Offline

#3 2020-07-09 14:08:03

rogeriomayer
Member
Registered: 2020-07-03
Posts: 12

Re: Show json array on buttons in a boot

Sorry, i got confused and send question in Portuguese, but my question is how to show multiple buttons from an array of a json response.
Example:

REST API response:
{
types: [
            {typeName:Button1},
            {typeName:Button2},
            {typeName:Button3}
            ]
}


Show in chat like this:

Hello choose an option
[Button1]    [Button2]   [Button3]  -> (button text from Json response)

Offline

#4 2020-07-09 14:27:39

remdex
Administrator
From: Lithuania
Registered: 2012-09-23
Posts: 3,661
Website

Re: Show json array on buttons in a boot

As you see here

quick_replies are an array.
https://doc.livehelperchat.com/docs/bot … g-location

Another option is the tip described in the same article.

Offline

#5 2020-07-16 13:08:39

rogeriomayer
Member
Registered: 2020-07-03
Posts: 12

Re: Show json array on buttons in a boot

Hello, thanks for the help initially it worked, the options for click appeared and executed the trigger (id 21, in payload)
but trigger id 21 executes another REST API, when executing the other REST API the variable {{msg}} is empty. How I pass the result
clicked from meta_msg to a second REST API? Thanks.

meta_msg": {
    "content": {
        "quick_replies": [
            {
                "content": {
                "name": "Option 1",
                "payload": "21"
            },
            "type": "trigger"
            },
            {
                "content": {
                "name": "Option 2",
                "payload": "21"
            },
            "type": "trigger"
            }
        ]
    }
}

Offline

#6 2020-07-16 13:13:26

remdex
Administrator
From: Lithuania
Registered: 2012-09-23
Posts: 3,661
Website

Re: Show json array on buttons in a boot

I'm not sure I understand...
Visitor clicks a button. You send Rest API call. You parse response. You can store some parts of Rest API call 1 in chat variables. https://doc.livehelperchat.com/docs/bot … out-coding
And later just reuse these in call 2 etc..

Offline

#7 2020-07-16 14:43:29

rogeriomayer
Member
Registered: 2020-07-03
Posts: 12

Re: Show json array on buttons in a boot

I created a variable ({"card": "11111111111"}) in Trigger type "Update Current Chat" and when I tried to call the Rest API in the Response Type "Execute Action". In my REST API I created a "Sub URL" like this {{card}}, did not recognize the value "http: / myurl / 11111111111" and called like this "http: / myurl / {{card}}". What can I have done wrong.

Thank you for your help.


{
        "_id": "F-hdyYb7s",
        "type": "command",
        "content": {
            "command": "chatvariable",
            "text": "{{msg}}",
            "payload": "{\"cartao\":\"11111111111\"}",
            "rest_api_method_output": {
                "temp1593794277247": "23"
            },
            "rest_api": "2",
            "attr_options": {
                "background_process": false,
                "collection_callback_match": "23",
                "collection_callback_pattern": "23"
            },
            "rest_api_method": "temp1593794242823",
            "event_background_inst": true,
            "event_background": false,
            "rest_api_method_params": [],
            "event": "cartao selecionado",
            "event_validate": "/(.*?)/"
        }
    },
    {
        "_id": "A3t0OQ6ME",
        "type": "actions",
        "content": {
            "text": "",
            "rest_api_method_output": [],
            "rest_api": "2",
            "attr_options": {
                "collection_callback_pattern": "23"
            },
            "rest_api_method": "temp1593794242823",
            "event_background_inst": false,
            "event_background": true,
            "rest_api_method_params": [],
            "events": [
                {
                    "_id": "IqYc0LiGi",
                    "type": "button",
                    "content": {
                        "identifier": "Executar UR86",
                        "trigger_id": "23"
                    }
                }
            ],
            "event_validate": "/(.*?)/"
        }
    }

Last edited by rogeriomayer (2020-07-16 14:46:18)

Offline

#8 2020-07-17 06:53:35

remdex
Administrator
From: Lithuania
Registered: 2012-09-23
Posts: 3,661
Website

Re: Show json array on buttons in a boot

I still don't get what you are trying to do.

See example how I set UUID from first Rest API response and later reuse it just.
https://doc.livehelperchat.com/docs/bot … out-coding

Offline

#9 2020-07-17 06:54:48

remdex
Administrator
From: Lithuania
Registered: 2012-09-23
Posts: 3,661
Website

Re: Show json array on buttons in a boot

And if you need more specific commercial support you can contact me on skype...

Offline

#10 2020-07-17 13:26:42

rogeriomayer
Member
Registered: 2020-07-03
Posts: 12

Re: Show json array on buttons in a boot

I just tried to create a variable and set a value like in the documentation {"card": "content_1"}, but I couldn't get the value in the REST API, or in another Trigger, instead of the set value "content_1" in the REST API the result is "{{card}}". As if the variable is not recognized. To create, just create the variable inside the Trigger or do you have any other steps? I saw another topic on the forum with the same problem, I believe it is some simple detail, but it is not clear how to use these variables.

"forum.livehelperchat.com/viewtopic.php?id=3672"

Thank you for your help.

Offline

#11 2020-07-17 13:36:24

remdex
Administrator
From: Lithuania
Registered: 2012-09-23
Posts: 3,661
Website

Re: Show json array on buttons in a boot

Well,

Documentation tells everything...

In rest API definition itself you have access to all these variables.
https://doc.livehelperchat.com/docs/bot … -variables

And in trigger itself you set custom chat variable just from first response..

Offline

#12 2020-07-17 14:00:19

remdex
Administrator
From: Lithuania
Registered: 2012-09-23
Posts: 3,661
Website

Re: Show json array on buttons in a boot

Custom variables is set here E.g first rest api call
https://doc.livehelperchat.com/docs/bot … ssage-send

Reused in next api call here
https://doc.livehelperchat.com/docs/bot … w-it-works

If you are collecting additional variables placehjolder in Rest API call will be
{{lhc.add. identifier}}

Offline

#13 2020-07-20 16:33:42

rogeriomayer
Member
Registered: 2020-07-03
Posts: 12

Re: Show json array on buttons in a boot

Hello, the variables finally worked, thanks for the help. However, a doubt arose.
I have a REST API returning a meta_msg, how can I collect the value that was clicked on the item?
Is there a way to show text on the button to the client and have another value that I will use in a variable to pass to a REST API, like a "text" and "id" of an html button?

Thanks.

meta_msg": {
    "content": {
        "quick_replies": [
            {
                "content": {
                "name": "Option 1",
                "payload": "21"  //Ex : "How in this trigger "21" collect the option clicked and put in a variable?"
            },
            "type": "trigger"
            },
            {
                "content": {
                "name": "Option 2",
                "payload": "21" //Ex : "How in this trigger "21" collect the option clicked and put in a variable?"
            },
            "type": "trigger"
            }
        ]
    }
}

Offline

#14 2020-07-20 16:46:13

remdex
Administrator
From: Lithuania
Registered: 2012-09-23
Posts: 3,661
Website

Re: Show json array on buttons in a boot

When you define a trigger there is an option to choose. Default trigger for unknown button click. As it’s your custom payloads as a message you will receive payload data smile which you can use in rest api as user msg smile

Offline

#15 2020-07-20 19:31:05

rogeriomayer
Member
Registered: 2020-07-03
Posts: 12

Re: Show json array on buttons in a boot

It wasn't clear to me how to do it this way, I tried and it didn't work.
Can i use store_name and store_value to set value in variable?

Do you have an example of how to do it?

Thank you

Last edited by rogeriomayer (2020-07-20 19:57:37)

Offline

#16 2020-07-20 19:34:03

remdex
Administrator
From: Lithuania
Registered: 2012-09-23
Posts: 3,661
Website

Re: Show json array on buttons in a boot

Default for unknown button click.
https://doc.livehelperchat.com/docs/bot … at-started

There you defined Rest API call as you do with regular messages and message itself will be just payload data.

Offline

#17 2020-07-20 19:58:27

rogeriomayer
Member
Registered: 2020-07-03
Posts: 12

Re: Show json array on buttons in a boot

Can i use store_name and store_value to set value in variable?

Offline

#18 2020-07-20 20:01:25

remdex
Administrator
From: Lithuania
Registered: 2012-09-23
Posts: 3,661
Website

Re: Show json array on buttons in a boot

I do not understand what is store_name or store_value... on button click tou execute trigger and with response you can do whatever you want

Offline

#19 2020-07-20 20:16:12

rogeriomayer
Member
Registered: 2020-07-03
Posts: 12

Re: Show json array on buttons in a boot

It worked by setting the value in the Store Name and Store Value fields, like the example. big_smile big_smile big_smile


"meta_msg": {
    "content": {
        "quick_replies": [
        {
            "content": {
            "button_id": "button_1",
            "name": "Button 1",
            "payload": "45",
            "store_name": "myvariable",
            "store_value": "xxxxxxxxxx"
            },
            "type": "trigger"
        },
        {
            "content": {
            "button_id": "button_2",
            "name": "Button 2",
            "payload": "45",
            "store_name": "myvariable",
            "store_value": "yyyyyyyyyyy"
            },
            "type": "trigger"
        },
    }
}

Offline

#20 2020-07-21 06:14:21

remdex
Administrator
From: Lithuania
Registered: 2012-09-23
Posts: 3,661
Website

Re: Show json array on buttons in a boot

Yes, that's a good trick smile forgot about that. Now you can improve documentation and create a pull request smile

https://github.com/LiveHelperChat/doc

Offline

#21 2021-07-28 20:27:50

karlitoxz
Member
Registered: 2021-02-10
Posts: 16

Re: Show json array on buttons in a boot

good day, I'm doing a Execute trigger body like this:

[
    {
        "type": "text",
        "content": {
            "text": "Please select the promissory note number.",
            "quick_replies": [
                {
                    "type": "trigger",
                    "content": {
                        "name": "custom text promissory 01",
                        "payload": "504",
                        "store_name": "myvariable",
                        "store_value": "0043652353"
                    }
                },
                {
                    "type": "trigger",
                    "content": {
                        "name": " custom text promissory 02 ",
                        "payload": "504",
                        "store_name": "myvariable",
                        "store_value": "0044106813"
                    }
                }
            ],
            "attr_options": {
                "as_dropdown": true,
                "hide_text_area": true
            }
        }
    }
]

but I have not been able to print the variable in a: Add response-> Send text; I have tried like this:

{lhc.var.myvariable} -
{args.chat.chat_variables_array.myvariable} -
{{args.chat.myvariable}} -
{{lhc.add. myvariable}} -

Please could you tell me how you did it, thank you.
---------------------- EDIT ----------------------

It had a spelling error (a space) is achieved like this:

{lhc.add.myvariable}

Last edited by karlitoxz (2021-07-30 21:24:41)

Offline

Board footer