Write and use multi-formats

You can use multiple formats

In main.js

import code from './main.converse'

export default {
    code,
    formats: {
        quickReplies(text, [actions]) {
            return {
                text,
                actions
            }
        },
        image(text, [image]) {
            return {
                text, 
                image
            }
        }
    }
}

In ConverseScript:

@Event('start')
start() {
    @Format('image', 'test.com')
    @Format('quickReplies', ['yes', 'no'])
    > test
}

the result is

{
    image: { text: 'test', image: 'test.com' },
    quickReplies: {
        text: { text: 'test', image: 'test.com' },
        actions: [ 'yes', 'no' ]
    }
}

Merge formats

In main.js

import code from './main.converse'

export default {
    code,
    formats: {
        quickReplies(text, [actions]) {
            return {
                text,
                actions
            }
        },
        image(text, [image]) {
            return {
                text, 
                image
            }
        }
    },
    mergeMultiFormats: true
}

In ConverseScript:

@Event('start')
start() {
    @Format('image', 'test.com')
    @Format('quickReplies', ['yes', 'no'])
    > test
}

the result is

{ 
    text: 'test', 
    actions: [ 'yes', 'no' ], 
    image: 'test.com' 
}

Last updated