samtecspg / articulate

A platform for building conversational interfaces with intelligent agents (chatbots)
http://spg.ai/projects/articulate/
Apache License 2.0
599 stars 159 forks source link

Use of Handlebars #495

Closed bkurowski closed 5 years ago

bkurowski commented 5 years ago

Question

Hi guys this might not be articulate problem but I'd rather ask you question here.

I am having this piece of JSON code:

{ "events": [{ "id": "123456", "eventDetectionTimestamp": "2019-01-18T20:44:20.924Z", "eventRecordTimestamp": "2019-01-18T20:44:27.168Z", "newValues": [{ "active": "true" }] }, { "id": "12345678", "eventDetectionTimestamp": "2019-01-18T20:44:26.805Z", "eventRecordTimestamp": "2019-01-18T20:44:33.566Z", "newValues": [{ "syncStatus": "Other" }] }] }

I am trying to access "newValues" using {{forEach}} handlebar as there are several information just like visible above. But it is not working out for me, I am trying to use this type of Agent Response.

{{#forEach webhookResponse.events}} {{newValues}} {{/forEach}}

The only thing I would like to view are the contents of "newValue". Would anyone give me hand with this ?

Thank you.

dcalvom commented 5 years ago

Hi @bkurowski,

As I see newValues have different representations, do you want to see the whole JSON or what values do you want to see from newValues, I mean in which format?

dcalvom commented 5 years ago

For example if you to display the whole content of newValues I would try this:

{{#each events}}
    {{{JSONstringify newValues}}}
{{/each}}

And that would generate this:

[
  {
    "active": "true"
  }
]
[
  {
    "syncStatus": "Other"
  }
]

In case you want to iterate each property I would use forOwn

bkurowski commented 5 years ago

I see, thank you, {{forOwn}} is the answer to my question. Thank you for your answer.

Just another question here, I was making a special query which contains massive amount of data. But i was having trouble with formatting the data, like adding "New Line" ("\n") so it is more user friendly.

Could you tell me if I will be able to reformat the data to be more user friendly in the new UI ?

wrathagom commented 5 years ago

Which data re you referring to? The response? The webhook? At the moment I don't think there are any improvements along those lines. Do you have any ideas how we can make this more friendly?

bkurowski commented 5 years ago

For example when I am receiving data from webhook that is an array and contains String inside with many sentences followed by "\n", I was hoping Articulate will understand "\n" or any similar like <br> . But as I observed before, it just fires the sentences on the chat one after the other and the user will not be able to see where is start and finish. I have completed this formatting on my custom chat client, but I was wondering if there would be a possibility to do it automatically inside Articulate in new UI. So no changes would have to be done on the custom chat.

wrathagom commented 5 years ago

the problem is that each platform treats it differently, so, yes we could make the Articulate UI okay with richer text, but that wouldn't mean Facebook or Slack would handle it as well. and very few people are chatting with the bot (other than the developer) in the ArticulateUI.

bkurowski commented 5 years ago

Oh I see what you mean. On the other hand what do you think of using some type of handlebar (Not sure if any exists) inside the Agent Response so we could apply {{newLine}} between any {{webhookResponse}} ? Or even something similar.

wrathagom commented 5 years ago

I'll open a new issue for Ubiquity handling richer formatting.