Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

correct mustache rendering from causing mutation of initial dialog script #1761

Merged
merged 5 commits into from
Oct 28, 2019
Merged

Conversation

InnoraG
Copy link
Contributor

@InnoraG InnoraG commented Aug 7, 2019

prevent mustache.render or parseTemplatesRecursive to mutate back line objects through copying to outgoing by value instead of reference using deepcopy format JSON.parse(JSON.stringify(line.xxxxx)) of objets like attachments, quick_replies or blocks

prevent mustache.render or parseTemplatesRecursive to change back line objects or dc objects by copying by value to outgoing instead of by reference
@InnoraG
Copy link
Contributor Author

InnoraG commented Sep 6, 2019

Adding example for better clarity :
In a sample multilang bot using mustache variable as template for translation, without deepcopy, the mustache template variable gets rendered permanently and disappear in "line" variable preventing rendering it over again

Sample rendering without deepcopy (QR text is fixed as initial value) :

NoDeepCopy2

Sample rendering with deepcopy (QR text can be translated using mustache in each turn) :

WithDeepCopy2

Copy link
Contributor

@adantoscano adantoscano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried with the following code

        let replies = new BotkitConversation('replies', controller);
        replies.ask({
            text: 'Click one of these suggestions!',
            quick_replies: [
                {
                    title: 'Foo',
                    payload: 'foo',
                },
                {
                    title: 'Bar',
                    payload: 'bar',
                }
            ]
        }, [], 'reply');
        replies.say({
            channelData: {
            attachment: {
              type: 'template',
              payload: {
                template_type: 'generic',
                elements: [
                  {
                    title: '{{vars.reply}}',
                    subtitle: '{{vars.reply}}',
                    image_url: `https://image.com`,
                    buttons: [
                      {
                        type: 'web_url',
                        url: 'https://google.com',
                        title: '{{vars.reply}}'
                      }
                    ]
                  }
                ]
              }
            }
        }});
        controller.addDialog(replies);

        controller.hears('qqq', 'message', async(bot, message) => {
            await bot.beginDialog('replies');
        });

Running twice, without changes, results in the same card clicking on diferent quick replies each time.

With @InnoraG changes running as expected!

@benbrown benbrown added this to the 4.6 milestone Sep 13, 2019
@benbrown benbrown merged commit 45f4ccf into howdyai:master Oct 28, 2019
@benbrown
Copy link
Contributor

Thank you!!

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

Successfully merging this pull request may close these issues.

3 participants