Suppose that you need your bot to interact in 2 or more languages, depending on the user preferences or the user device default language.


The first step is to store this language as a Global Variable for the specific user. You can do this in fllow using the change Node. 



Then each time, the user interact with the bot, fetch this preferred language.

And finally, use the Swicth Node to direct the Bot to the right worrding








[{"id":"636c5035.a07a1","type":"function","z":"e48f5b2c.c62ca8","name":"Send Message Fr","func":"msg.url = \"https://\"+env.get('BASE_URL')+'/_matrix/client/r0/rooms/' +msg.room_id+ '/send/m.room.message?access_token='+msg.bot_access_token\nmsg.headers ={\n //   \"Authorization\" : \"Bearer sk_test_LYtqjhDKfkXv3fOmb4PT4va400SSWORV4p\",\n    \"Content-type\": \"application/json\"\n}\n\nmsg.payload=\n{\n    \"msgtype\": \"m.text\",\n    \"body\": \"To Get Started, Please connect to you MovieDB Account and paste the Code retrived here\"\n\n}\n\n\n//msg.payload={\n      //  \"body\": env.get('message'), //\"This is an example text message\",\n       // \"msgtype\": \"m.text\"\n//}\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":530,"y":100,"wires":[["7ea953f3.158cac"]],"icon":"node-red-contrib-chatbot/chatbot-conversation.png"},{"id":"7ea953f3.158cac","type":"http request","z":"e48f5b2c.c62ca8","name":"","method":"POST","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","x":675,"y":120,"wires":[[]],"l":false},{"id":"4ce555fb.ccbcec","type":"function","z":"e48f5b2c.c62ca8","name":"Send Message En","func":"msg.url = \"https://\"+env.get('BASE_URL')+'/_matrix/client/r0/rooms/' +msg.room_id+ '/send/m.room.message?access_token='+msg.bot_access_token\nmsg.headers ={\n //   \"Authorization\" : \"Bearer sk_test_LYtqjhDKfkXv3fOmb4PT4va400SSWORV4p\",\n    \"Content-type\": \"application/json\"\n}\n\nmsg.payload=\n{\n    \"msgtype\": \"m.text\",\n    \"body\": \"To Get Started, Please connect to you MovieDB Account and paste the Code retrived here\"\n\n}\n\n\n//msg.payload={\n      //  \"body\": env.get('message'), //\"This is an example text message\",\n       // \"msgtype\": \"m.text\"\n//}\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":530,"y":140,"wires":[["7ea953f3.158cac"]],"icon":"node-red-contrib-chatbot/chatbot-conversation.png"},{"id":"33c07161.5239be","type":"switch","z":"e48f5b2c.c62ca8","name":"","property":"language","propertyType":"msg","rules":[{"t":"eq","v":"Fr","vt":"str"},{"t":"eq","v":"En","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":3,"x":310,"y":120,"wires":[["636c5035.a07a1"],["4ce555fb.ccbcec"],["4ce555fb.ccbcec"]]}]


Other Options to consider

Sometimes, for maintenance reasons or simplicity, you may split your Bot into multiples Bots in each language.

The default bot will onbord the user then either:

- redirect the user to the Bot of his language

- invite the target Bot to the room as admin, and then leave the room.