Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[help] How to use mustache variables as an array, dynamically? #1094

Closed
gcfabri opened this issue Oct 16, 2017 · 3 comments
Closed

[help] How to use mustache variables as an array, dynamically? #1094

gcfabri opened this issue Oct 16, 2017 · 3 comments

Comments

@gcfabri
Copy link

gcfabri commented Oct 16, 2017

I store inline messages and structured messages in separate files from business logic.
Out of message files, when I set a variable like this:

bot.js:

//...
convo.setVar(`sample`, `foobar`);
//...

and then make a reference in this file inline_messages.js:

export default {
  myMessage: `This is my variable: {{ vars.sample }}`
}

and use it on any conversation, it works nicely.
This is my variable: foobar

How can I use this as an array to build a structured message dynamically (eg.: Facebook Generic Template)? There is a way to do it using Mustache lib or Botkit?

Please, take a look:

bot.js:

convo.setVar(`sample`, [{ cod: '1', value: 'foo' },{ cod: '2', value: 'bar' }]);

structured_messages.js:

export default {
  myStructuredMessage: {
    type: `message`,
    text: ``,
    attachments: [ 
      // How to iterate this array saved on variable 'sample' and use it to build this structure dynamically? 
    ]
  }
}
@gcfabri gcfabri changed the title [help] How use mustache variables as an array, dynamically? [help] How to use mustache variables as an array, dynamically? Oct 16, 2017
@benbrown
Copy link
Contributor

There is not currently a way to dynamically generate attachments based on variables.

This is definitely something we're interested in adding, but I haven't decided on how it should work yet. Any thoughts?

@akhanukov
Copy link

Before I knew what Mustache Script was, and/or when I need global variables, I'm usually pulling from a database (via API) of messages tied to a common topic, flow, conversation, or what we call "interactions", and build an array of those messages with keys as message IDs as @benbrown taught me. Those are of course navigated between using changeTopic or whatever but that's neither here nor there.

However, the places where we need additional variables, within the "output messages array", we simply do a find and replace where we use something like a WordPress shortcode notation, ie. [variable1] or in some cases something made up like -_- , natch. ;) So basically, doing what Mustache is created to alleviate, I think.

See, the problem I have, is: if build a wealth of Conversations (Topics, Flows, convos basically), and in addition to jumping around within that topic or conversation tree, I want to jump between topics, I write my own filter in the on or hears handler which works. However, that creates a new tree and any convo variables go bye bye. I thought of using server variables like how I store my Customer ID in the command to run my bot.js file, but that seems... wrong? I get why I don't want to store sensitive or even temporary variables in a MySQL nor even a NoSQL database, but what's the best way to do both what @gcfabri and/or I need? (If this is a separate issue, let me know and I'll create a ticket to discuss.) Thanks!

@stale
Copy link

stale bot commented Oct 22, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants