Last active
September 9, 2020 19:11
-
-
Save andrevandal/58cf6367368a704085ecab81245c4512 to your computer and use it in GitHub Desktop.
blip script dynamic menu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
function run(source) { | |
var isWhatsApp = source === "WhatsApp"; | |
var csTypes = ["Certificado Digital", "DFe", "Fintech", "Mobile"]; | |
var menuTitle = "Qual tipo de atendimento você deseja?"; | |
var template = function template(e, i) { | |
return isWhatsApp ? "*" + ++i + "*: " + e : "{\"text\": " + e + ", \"previewText\": " + e + ", \"value\": null, \"index\": " + i + ", \"type\": null }"; | |
}; | |
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | |
args[_key - 1] = arguments[_key]; | |
} | |
var options = args.filter(function (e) { | |
return e !== null; | |
}).map(function (e, i) { | |
return "Falar com " + (e === "true" ? csTypes[i] : e + ' - ' + csTypes[i]); | |
}) || []; | |
var menuOptions = [].concat(options).map(function (e, i) { | |
return template(e, i); | |
}); | |
var content = isWhatsApp ? menuTitle + "\n\n" + menuOptions.join('\n') : { | |
"text": menuTitle, | |
options: menuOptions | |
}; | |
return JSON.stringify(content); | |
} | |
/* código original ES6+ | |
function run (source, ...args) { | |
const isWhatsApp = source === "WhatsApp" | |
const csTypes = ["Certificado Digital", "DFe", "Fintech", "Mobile"] | |
const menuTitle = "Qual tipo de atendimento você deseja?" | |
const template = (e, i) => (isWhatsApp ? `*${++i}*: ${ e }` : `{"text": ${e}, "previewText": ${e}, "value": null, "index": ${i}, "type": null }`) | |
const options = args.map((e, i) => `Falar com ${e === "true" ? csTypes[i] : e + ' - ' + csTypes[i]}`) || [] | |
const menuOptions = [...options].map((e, i) => (template(e, i))) | |
const content = isWhatsApp ? | |
`${menuTitle}\n\n${menuOptions.join('\n')}` | |
: { | |
"scope": "immediate", | |
"text": menuTitle, | |
options: menuOptions | |
} | |
return JSON.stringify(content) | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment