hi there!
I'm doing a chatbot for instagram, and I came across a situation. I made a script to put in an array each messages that the bot returns, but it returns with some messages with order exchanged/shuffled. So I applied a delay node. But I wanted to put an async function to improve performance.
Would there be a node that does this function?
below the flow diagram
[{"id":"38728f55c6274ca7","type":"function","z":"a356a8194128f9f2","name":"main function// async..await","func":"//tipo da mensagem\nvar typemsg = msg.payload.type;\n\n//id da mensagem\nconst chatId = msg.payload.chatId;\n\n//opções criadas no nó anterior\nvar options = msg.payload.options;\n\n//id da sessão\nvar sessionId = msg.payload.session_id;\n\n//conteúdo da mensagem\nvar msgMsg = msg.payload.content;\n\n//tamanho do array da mensagem\nvar tamanho = msg.payload.content.length;\n\n//array que receberá as novas mensagens\nvar newMsg = await [];\nconsole.log(newMsg);\n//refatorar loop para aplicar função assincrona\n\nlet controleMsg = async () => {\nfor (const lines of msgMsg){\n if(lines.response_type == \"text\"){\n newMsg.push({\n payload:{\n type:typemsg,\n chatId:chatId,\n session_id: sessionId,\n content:lines.text,\n response_type: lines.response_type,\n \n }\n })}else{\n newMsg.push({\n payload:{\n type:typemsg,\n chatId:chatId,\n session_id: sessionId,\n content:lines.title,\n response_type: lines.response_type,\n options: options\n \n }\n })}\n}\nreturn [newMsg];\n}\n\n\n\n\n\n\n//retorna as mensagens para o novo array\n\n\n\n//futuramente será incerido função assincrona.\n//ver função for...of JavaScript","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":220,"y":740,"wires":[[]]}]
but to advance, the function that is checking is this:
I tried to apply an async function and return the contents to the array, but it doesn't debug.
//type of msg
var typemsg = msg.payload.type;
//id of msg
const chatId = msg.payload.chatId;
//menu options
var options = msg.payload.options;
//id da sessão
var sessionId = msg.payload.session_id;
//content of mensagem
var msgMsg = msg.payload.content;
//array that will receive as new messages
var newMsg = await [];
let controleMsg = async () => {
for (const lines of msgMsg){
if(lines.response_type == "text"){
newMsg.push({
payload:{
type:typemsg,
chatId:chatId,
session_id: sessionId,
content:lines.text,
response_type: lines.response_type,
}
})}else{
newMsg.push({
payload:{
type:typemsg,
chatId:chatId,
session_id: sessionId,
content:lines.title,
response_type: lines.response_type,
options: options
}
})}
}
}
return [newMsg];