Skip to content

Commit

Permalink
custom msgs
Browse files Browse the repository at this point in the history
  • Loading branch information
nocodeleaks committed May 9, 2024
1 parent 52d0ce0 commit 9f2f7a3
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 87 deletions.
7 changes: 4 additions & 3 deletions extra/n8n+chatwoot/ChatwootToQuepasa.json
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@
},
{
"parameters": {
"jsCode": "const response = [];\nfor (const item of $input.all()) {\n const body = item.json.body;\n if (body) { \n \n // obsolete, marked for remove, 2024/04/25\n const token = item.json.extra.token;\n\n // default extra content\n const extra = item.json.extra;\n\n let chatId = body.conversation.meta?.sender?.identifier; \n if (!chatId)\n {\n chatId = body.conversation.meta?.sender?.custom_attributes?.quepasa;\n if (!chatId) {\n chatId = body.conversation.meta?.sender?.phone_number;\n }\n }\n\n // for each message, *not common to be more than one\n for (const message of body.conversation.messages) \n { \n const payload = {};\n payload.chatid = chatId;\n payload.inreply = message.content_attributes?.in_reply_to_external_id;\n payload.conversationid = body.conversation.id ?? message.conversation_id;\n \n // obsolete, marked for remove, 2024/04/25\n payload.token = token;\n\n // -------------------------------------\n \n if (message.content_type === 'integrations' && message.content_attributes?.type === 'dyte') \n message.content += '\\r\\n *** https://app.dyte.in/meeting/stage/' + message.content_attributes?.data.room_name; \n \n if (message.content) {\n\n // leading with \\ at SHIFT+ENTER\n message.content = message.content.replace(/\\n\\\\/g,\"\\n\").replace(/ \\\\/g,\"\");\n \n payload.messageid = message.id; \n payload.content= message.content; \n \n const sender = message.sender?.available_name || message.sender?.name || 'Auto Atendimento';\n \n const customs = body.conversation.meta?.sender?.custom_attributes;\n const pat = !((customs?.hasOwnProperty('skipagenttitle') ?? false) && (customs?.skipagenttitle ?? false));\n\n if (pat) payload.sender = sender;\n\n // appending to response as new item\n response.push({ payload: payload, extra: extra });\n }\n\n if (message.attachments) {\n let counter = 0;\n for (const attach of message.attachments) \n {\n // fixed payload counter for multiples attachs, 2024/05/06\n const attachmentPayload = { ...payload }; // Criando uma nova instância de payload\n attachmentPayload.messageid = message.id + '-a' + counter++; \n attachmentPayload.attachment = attach.data_url;\n \n // appending to response as new item\n response.push({ payload: attachmentPayload, extra: extra }); \n }\n } \n }\n }\n}\n\nreturn response;"
"jsCode": "const response = [];\nfor (const item of $input.all()) {\n const body = item.json.body;\n if (body) { \n \n // obsolete, marked for remove, 2024/04/25\n const token = item.json.extra.token;\n\n // default extra content\n const extra = item.json.extra;\n\n let chatId = body.conversation.meta?.sender?.identifier; \n if (!chatId)\n {\n chatId = body.conversation.meta?.sender?.custom_attributes?.quepasa;\n if (!chatId) {\n chatId = body.conversation.meta?.sender?.phone_number;\n }\n }\n\n // for each message, *not common to be more than one\n for (const message of body.conversation.messages) \n { \n const payload = {};\n payload.chatid = chatId;\n payload.inreply = message.content_attributes?.in_reply_to_external_id;\n payload.conversationid = body.conversation.id ?? message.conversation_id;\n \n // obsolete, marked for remove, 2024/04/25\n payload.token = token;\n\n // -------------------------------------\n \n if (message.content_type === 'integrations' && message.content_attributes?.type === 'dyte') \n message.content += '\\r\\n *** https://app.dyte.in/meeting/stage/' + message.content_attributes?.data.room_name; \n\n // leading with \\ at SHIFT+ENTER\n if (message.content) \n {\n message.content = message.content.replace(/\\n\\\\/g,\"\\n\").replace(/ \\\\/g,\"\");\n payload.content = message.content; \n }\n \n // should create an extra message for caption ?\n const textmsg = (!message.attachments) || (message.attachments.length > 1);\n \n if (message.content && textmsg) { \n payload.messageid = `${message.id}`; // ensure as string \n \n const sender = message.sender?.available_name || message.sender?.name || 'Auto Atendimento';\n \n const customs = body.conversation.meta?.sender?.custom_attributes;\n const pat = !((customs?.hasOwnProperty('skipagenttitle') ?? false) && (customs?.skipagenttitle ?? false));\n\n if (pat) payload.sender = sender;\n\n // appending to response as new item\n response.push({ payload: { ...payload }, extra: extra });\n payload.content = undefined;\n }\n\n if (message.attachments) {\n let counter = 0;\n for (const attach of message.attachments) \n {\n // fixed payload counter for multiples attachs, 2024/05/06\n const attachmentPayload = { ...payload }; // Criando uma nova instância de payload\n attachmentPayload.messageid = `${message.id}-a${counter++}`; // ensure as string, adding an attach counter \n attachmentPayload.attachment = attach.data_url;\n \n // appending to response as new item\n response.push({ payload: attachmentPayload, extra: extra }); \n }\n } \n }\n }\n}\n\nreturn response;"
},
"id": "21f4f961-7d92-4882-a375-bbdda1a83f37",
"name": "Payload",
Expand Down Expand Up @@ -949,7 +949,7 @@
},
{
"parameters": {
"content": "## (1.0.26) Updates\n* adjust payload for attachs\n\n## Recommendations \n* Remember set timeout to 30 seconds",
"content": "## (1.0.27) Updates\n* adjust payload for attachs and text msgs\n* attach filename decode\n\n## Recommendations \n* Remember set timeout to 30 seconds",
"height": 184.30667672289223,
"width": 457.17616077915915
},
Expand Down Expand Up @@ -1414,6 +1414,7 @@
"text": "={{$json.payload.content}}",
"chatId": "={{$json.payload.chatid}}",
"url": "={{$json.payload.attachment}}",
"filename": "={{decodeURI($json.payload.attachment.split('/').at(-1))}}",
"trackId": "chatwoot",
"inReply": "={{$json.payload.inreply}}"
},
Expand Down Expand Up @@ -2327,7 +2328,7 @@
"executionTimeout": 50,
"executionOrder": "v1"
},
"versionId": "723444f1-9110-4303-aa4e-d2e99124acba",
"versionId": "d53c6130-6ae4-44ae-9afc-49c6eb4d1072",
"meta": {
"templateCredsSetupCompleted": true,
"instanceId": "2b4ab318d4f8eba20155e50db9998481bc305e3588e42ee69176091736c9d07e"
Expand Down
8 changes: 6 additions & 2 deletions extra/n8n+chatwoot/GetChatwootContacts.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@
{
"name": "fromme",
"value": "={{$json.body.fromme}}"
},
{
"name": "edited",
"value": "={{$json.body.edited}}"
}
]
},
Expand Down Expand Up @@ -400,7 +404,7 @@
},
{
"parameters": {
"content": "## (1.0.10) Updates\n* type number to text\n\n## Recommendations \n* Remember set timeout to 20 seconds",
"content": "## (1.0.11) Updates\n* missing edited parameter\n\n## Recommendations \n* Remember set timeout to 20 seconds",
"height": 201.45401153644474,
"width": 467.54452018877896
},
Expand Down Expand Up @@ -1023,7 +1027,7 @@
"callerPolicy": "workflowsFromSameOwner",
"executionTimeout": 30
},
"versionId": "de135da2-ba1e-4971-91d6-3b578101d46b",
"versionId": "d59193ff-903a-4de3-8570-0460bc110e27",
"meta": {
"templateCredsSetupCompleted": true,
"instanceId": "2b4ab318d4f8eba20155e50db9998481bc305e3588e42ee69176091736c9d07e"
Expand Down
150 changes: 75 additions & 75 deletions extra/n8n+chatwoot/PostToChatwoot.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,27 +137,6 @@
780
]
},
{
"parameters": {
"values": {
"string": [
{
"name": "payload.content",
"value": "! \"Algum EMOJI\" | \"Alguma Reação que o sistema não entende ainda ..\""
}
]
},
"options": {}
},
"id": "d4a3eabf-64cb-440b-9726-dc95bea29f97",
"name": "Set Custom Content",
"type": "n8n-nodes-base.set",
"typeVersion": 1,
"position": [
-1420,
1060
]
},
{
"parameters": {
"content": "## Fail Retry \nImportant to retry on fail because if you are using any external storage, it will try to save at this time.\nSo you need to ensure success ...",
Expand All @@ -169,8 +148,8 @@
"type": "n8n-nodes-base.stickyNote",
"typeVersion": 1,
"position": [
2120,
1380
2340,
1400
]
},
{
Expand Down Expand Up @@ -204,7 +183,7 @@
},
{
"parameters": {
"content": "## (1.0.15) Updates\n* issue at msg with attachment and empty content\n\n## Recommendations \n* Remember set timeout to 10 seconds",
"content": "## (1.0.16) Updates\n* environment variables for custom contents\n\n## Recommendations \n* Remember set timeout to 10 seconds",
"height": 189.357048321488,
"width": 489.8474320052134
},
Expand Down Expand Up @@ -664,27 +643,6 @@
1060
]
},
{
"parameters": {
"values": {
"string": [
{
"name": "payload.content",
"value": "=**Localização:** \n{{ $json.attachment.url }}"
}
]
},
"options": {}
},
"id": "33c5378a-afa4-470e-840b-f59ea84e3855",
"name": "Override Default Content",
"type": "n8n-nodes-base.set",
"typeVersion": 1,
"position": [
980,
1500
]
},
{
"parameters": {
"conditions": {
Expand Down Expand Up @@ -792,7 +750,7 @@
"string": [
{
"name": "payload.content",
"value": "=⚠️ ***Essa mensagem foi editada !***\n -------------------------------------\n{{ $json.payload.content }}"
"value": "={{ $env['C8Q_MSGFOR_EDITED_CONTENT'] ?? '\\u26A0\\uFE0F ***Essa mensagem foi editada !***' }}\n\n-------------------------------------\n{{ $json.payload.content }}"
},
{
"name": "payload.content_attributes.in_reply_to_external_id",
Expand Down Expand Up @@ -920,20 +878,62 @@
"string": [
{
"name": "payload.content",
"value": "= ** Falha ao baixar anexo ! :: => {{ $json[\"attachment\"][\"filename\"] }}\n------------------------\nerror: {{ $json.error }}"
"value": "={{ $env['C8Q_MSGFOR_UNKNOWN_CONTENT'] ?? '! \"Algum EMOJI\" | \"Alguma Reação que o sistema não entende ainda ..\"' }}"
}
]
},
"options": {}
},
"id": "d4a3eabf-64cb-440b-9726-dc95bea29f97",
"name": "Set Unknown Content",
"type": "n8n-nodes-base.set",
"typeVersion": 1,
"position": [
-1420,
1060
]
},
{
"parameters": {
"values": {
"string": [
{
"name": "payload.content",
"value": "={{ $env['C8Q_MSGFOR_ATTACHERROR_CONTENT'] ?? '** Falha ao baixar anexo !' }}\n\n-------------------------------------\nfilename: {{ $json[\"attachment\"][\"filename\"] }}\nerror: {{ $json.error }}"
}
]
},
"options": {}
},
"id": "b71393b4-a75d-45e5-ac16-168db47123cc",
"name": "(In) Prepend error on content",
"name": "(In) Prepend Attach Error Content",
"type": "n8n-nodes-base.set",
"typeVersion": 1,
"position": [
-860,
700
]
},
{
"parameters": {
"values": {
"string": [
{
"name": "payload.content",
"value": "= {{ $env['C8Q_MSGFOR_LOCALIZATION_CONTENT'] ?? '** Localização **' }}\n\n-------------------------------------\n{{ $json.attachment.url }}"
}
]
},
"options": {}
},
"id": "33c5378a-afa4-470e-840b-f59ea84e3855",
"name": "Override Localization Content",
"type": "n8n-nodes-base.set",
"typeVersion": 1,
"position": [
980,
1500
]
}
],
"pinData": {},
Expand Down Expand Up @@ -1038,7 +1038,7 @@
"main": [
[
{
"node": "(In) Prepend error on content",
"node": "(In) Prepend Attach Error Content",
"type": "main",
"index": 0
}
Expand All @@ -1052,17 +1052,6 @@
]
]
},
"Set Custom Content": {
"main": [
[
{
"node": "No Operation, do nothing5",
"type": "main",
"index": 0
}
]
]
},
"Defaults": {
"main": [
[
Expand Down Expand Up @@ -1184,7 +1173,7 @@
"main": [
[
{
"node": "Override Default Content",
"node": "Override Localization Content",
"type": "main",
"index": 0
}
Expand Down Expand Up @@ -1341,17 +1330,6 @@
]
]
},
"Override Default Content": {
"main": [
[
{
"node": "If Has Thumbnail",
"type": "main",
"index": 0
}
]
]
},
"If Has Thumbnail": {
"main": [
[
Expand Down Expand Up @@ -1503,7 +1481,7 @@
],
[
{
"node": "Set Custom Content",
"node": "Set Unknown Content",
"type": "main",
"index": 0
}
Expand All @@ -1521,7 +1499,18 @@
]
]
},
"(In) Prepend error on content": {
"Set Unknown Content": {
"main": [
[
{
"node": "No Operation, do nothing5",
"type": "main",
"index": 0
}
]
]
},
"(In) Prepend Attach Error Content": {
"main": [
[
{
Expand All @@ -1531,6 +1520,17 @@
}
]
]
},
"Override Localization Content": {
"main": [
[
{
"node": "If Has Thumbnail",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
Expand All @@ -1539,7 +1539,7 @@
"callerPolicy": "workflowsFromSameOwner",
"executionTimeout": 10
},
"versionId": "51b207b3-3ebb-4291-b0c7-b88ed0ef22b4",
"versionId": "6e864ec7-471b-4449-ba1b-c81431bce1d1",
"meta": {
"templateCredsSetupCompleted": true,
"instanceId": "2b4ab318d4f8eba20155e50db9998481bc305e3588e42ee69176091736c9d07e"
Expand Down
6 changes: 3 additions & 3 deletions extra/n8n+chatwoot/QuepasaToChatwoot.json
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@
},
{
"parameters": {
"content": "## (1.0.13) Updates\n* extra parameter soc\n\n## Recommendations \n* Remember set timeout to 30 seconds",
"content": "## (1.0.14) Updates\n* custom content for revoked msgs\n\n## Recommendations \n* Remember set timeout to 30 seconds",
"height": 200.52521040961017,
"width": 398.97654103837476
},
Expand Down Expand Up @@ -1124,7 +1124,7 @@
"allowUnauthorizedCerts": true,
"jsonParameters": true,
"options": {},
"bodyParametersJson": "={\n \"private\": false,\n \"content\": \"Essa mensagem foi apagada !\",\n \"message_type\": 2,\n \"content_attributes\": { \n \"in_reply_to\": {{ +$json.revoked.id }},\n \"in_reply_to_external_id\": \"{{ $json.body.id }}\"\n },\n \"content_type\": \"text\"\n}",
"bodyParametersJson": "={\n \"private\": false,\n \"content\": \"{{ $env['C8Q_MSGFOR_REVOKED'] ?? '\\u274C Essa mensagem foi apagada !!!' }}\",\n \"message_type\": 2,\n \"content_attributes\": { \n \"in_reply_to\": {{ +$json.revoked.id }},\n \"in_reply_to_external_id\": \"{{ $json.body.id }}\"\n },\n \"content_type\": \"text\"\n}",
"headerParametersJson": "={ \"api_access_token\": \"{{ $json.body.extra.atoken }}\" }"
},
"name": "Send Revoked Message",
Expand Down Expand Up @@ -2195,7 +2195,7 @@
"executionTimeout": 30,
"executionOrder": "v1"
},
"versionId": "2c97dfdb-5f5b-4452-a1dd-16bfa452169c",
"versionId": "6ba2bcb1-332d-4fb1-8fed-bbe92670bb09",
"meta": {
"templateCredsSetupCompleted": true,
"instanceId": "2b4ab318d4f8eba20155e50db9998481bc305e3588e42ee69176091736c9d07e"
Expand Down
8 changes: 4 additions & 4 deletions extra/n8n+chatwoot/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
### Workflows links

* [(1.0.1) Chatwoot Profile Update](https://raw.githubusercontent.com/nocodeleaks/quepasa/main/extra/n8n%2Bchatwoot/ChatwootProfileUpdate.json)
* [(1.0.26) Chatwoot To Quepasa](https://raw.githubusercontent.com/nocodeleaks/quepasa/main/extra/n8n%2Bchatwoot/ChatwootToQuepasa.json)
* [(1.0.27) Chatwoot To Quepasa](https://raw.githubusercontent.com/nocodeleaks/quepasa/main/extra/n8n%2Bchatwoot/ChatwootToQuepasa.json)
* [(1.0.2) Chatwoot To Quepasa Greetings](https://raw.githubusercontent.com/nocodeleaks/quepasa/main/extra/n8n%2Bchatwoot/ChatwootToQuepasaGreetings.json)
* [(1.0.15) Post To Chatwoot](https://raw.githubusercontent.com/nocodeleaks/quepasa/main/extra/n8n%2Bchatwoot/PostToChatwoot.json)
* [(1.0.16) Post To Chatwoot](https://raw.githubusercontent.com/nocodeleaks/quepasa/main/extra/n8n%2Bchatwoot/PostToChatwoot.json)
* [(1.0.4) Quepasa Automatic](https://raw.githubusercontent.com/nocodeleaks/quepasa/main/extra/n8n%2Bchatwoot/QuepasaAutomatic.json)
* [(1.0.5) Quepasa Chat Control](https://raw.githubusercontent.com/nocodeleaks/quepasa/main/extra/n8n%2Bchatwoot/QuepasaChatControl.json)
* [(1.0.9) Quepasa Inbox Control](https://raw.githubusercontent.com/nocodeleaks/quepasa/main/extra/n8n%2Bchatwoot/QuepasaInboxControl.json)
* [(1.0.1) Quepasa Qrcode](https://raw.githubusercontent.com/nocodeleaks/quepasa/main/extra/n8n%2Bchatwoot/QuepasaQrcode.json)
* [(1.0.13) Quepasa To Chatwoot](https://raw.githubusercontent.com/nocodeleaks/quepasa/main/extra/n8n%2Bchatwoot/QuepasaToChatwoot.json)
* [(1.0.10) Get Chatwoot Contacts](https://raw.githubusercontent.com/nocodeleaks/quepasa/main/extra/n8n%2Bchatwoot/GetChatwootContacts.json)
* [(1.0.14) Quepasa To Chatwoot](https://raw.githubusercontent.com/nocodeleaks/quepasa/main/extra/n8n%2Bchatwoot/QuepasaToChatwoot.json)
* [(1.0.11) Get Chatwoot Contacts](https://raw.githubusercontent.com/nocodeleaks/quepasa/main/extra/n8n%2Bchatwoot/GetChatwootContacts.json)
* [(1.0.1) Post To WebCallBack](https://raw.githubusercontent.com/nocodeleaks/quepasa/main/extra/n8n%2Bchatwoot/PostToWebCallBack.json)
* [(1.0.1) Chatwoot Extra](https://raw.githubusercontent.com/nocodeleaks/quepasa/main/extra/n8n%2Bchatwoot/ChatwootExtra.json)

Expand Down

0 comments on commit 9f2f7a3

Please sign in to comment.