Link two Discord chats with different languages with local LibreTranslate

Hi, folks!

For curiosity i'm trying to use Node-RED for virtually linking two or more Discord chats in one stream.
The goal is to provide two or more roms with different languages which are linked by Hode-RED flow translation in a virtually one logical stream.

So say german-speaking users have german-translated chat where all the other room messages translated into german and, say, english-speaking users have english-translated chat where all german megssages are translated to english.

Now i have two needed dockerfiles running:

  1. Node-RED, with appropriate Discord and Telegram libraries;
  2. Working LibreTranslate image with all needed language translations.

Please, help me to properly tune Node-RED flow.

LibreTranslate accepts two forms of requests:

  1. Simple http in a form like
    http://192.168.1.200:8099/?source=en&target=de&q=Good%2520morning

  2. JSON like

const res = await fetch("http://192.168.1.200:8099/translate", {
	method: "POST",
	body: JSON.stringify({
		q: "Good morning",
		source: "en",
		target: "de",
		format: "text",
		api_key: ""
	}),
	headers: { "Content-Type": "application/json" }
});

console.log(await res.json());

I suppose such a low must do the basic translation, but some parameters are wrong.

Flow
Flow_template
Flow_debug

Ah, yes, i can resolve by myself and some googling.
We need to set JSON parameters like this
function

And next we easily get things done.

[
    {
        "id": "f6f2187d.f17ca8",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": ""
    },
    {
        "id": "6d363c32d59f323b",
        "type": "discordMessage",
        "z": "f6f2187d.f17ca8",
        "name": "Get Discord Post",
        "channelIdFilter": "",
        "token": "",
        "x": 240,
        "y": 80,
        "wires": [
            [
                "64832d8899fc9998"
            ]
        ],
        "outputLabels": [
            "out"
        ]
    },
    {
        "id": "69c0e6859f15e852",
        "type": "http request",
        "z": "f6f2187d.f17ca8",
        "name": "POST to LibreTranslate",
        "method": "POST",
        "ret": "txt",
        "paytoqs": "ignore",
        "url": "",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "",
        "senderr": false,
        "headers": [],
        "x": 270,
        "y": 240,
        "wires": [
            [
                "9e12064871090d1a"
            ]
        ]
    },
    {
        "id": "f43058dbf67fbd5e",
        "type": "discordMessageManager",
        "z": "f6f2187d.f17ca8",
        "name": "Post Translated message",
        "channel": "",
        "token": "",
        "x": 250,
        "y": 480,
        "wires": [
            []
        ]
    },
    {
        "id": "64832d8899fc9998",
        "type": "function",
        "z": "f6f2187d.f17ca8",
        "name": "Set request params",
        "func": "msg.method = \"POST\"\nmsg.url = \"http://192.168.1.200:8099/translate\"\nmsg.headers = {}\nmsg.headers[\"content-type\"] = \"application/json\"\nvar load = msg.payload\nmsg.payload = {}\nmsg.payload[\"q\"] = load\nmsg.payload[\"source\"] = \"en\"\nmsg.payload[\"target\"] = \"de\"\nmsg.payload[\"format\"] = \"text\"\nmsg.payload[\"api_key\"] = \"\"\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 270,
        "y": 160,
        "wires": [
            [
                "69c0e6859f15e852"
            ]
        ]
    },
    {
        "id": "9e12064871090d1a",
        "type": "json",
        "z": "f6f2187d.f17ca8",
        "name": "Convert payload",
        "property": "payload",
        "action": "obj",
        "pretty": false,
        "x": 260,
        "y": 320,
        "wires": [
            [
                "2998c0b31c6bcaa8"
            ]
        ]
    },
    {
        "id": "2998c0b31c6bcaa8",
        "type": "function",
        "z": "f6f2187d.f17ca8",
        "name": "Set request params",
        "func": "var load = msg.payload.translatedText\nmsg.payload = load\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 250,
        "y": 400,
        "wires": [
            [
                "f43058dbf67fbd5e"
            ]
        ]
    }
]

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.