Multi language bot

Hello i want to create multi language bot (Arabic and English) using simple method (i dont know if this applicable or not). i want to make a slot that check if the RegEx of the English letters appears or not and if it appear it should respond by the English response. if it didnt appear response by the Arabic text the issue that i cant have value in the conditional response that contains the RegEx.

entities:
- number
- phone_number
- kind
- English
slots:
  English:
    type: categorical
    values:
      - [a-zA-Z]
    influence_conversation: False
    mappings:
      - type: from_entity
        entity: English

responses:
  utter_greet:
    - condition:
        - type: slot
          name: English
          value: [a-zA-Z]
      text: Hey! how i can help you?
    - text: اهلا, عامل ايه
stories:

- story: hello
  steps:
  - intent: greet
  - action: utter_greet
  - intent: affirm
  - action: utter_tell_me_more
  - intent: deny
  - action: utter_goodbye

just want to make the bot check if there any English letters that’s mean you need to respond in English if you didn’t find respond. i hope my topic is clear

Welcome to the forum, Samer :slight_smile:

It sure is possible to make a bilingual bot! Take a loot at my bot that understands English, French, Arabic, Arabish, and Armenian.

What I did was use a slot called language that the user sets, and the bot will always respond in that language no matter which one the user speaks in.

I have seen and thought of many different ways to implement many languages in a bot, but the way you want to do it is so simple and really interesting. In fact it works because your languages’ alphabets are completely different - that wouldn’t work for e.g. English and French, or Arabic and Farsi.


What I recommend doing is checking the language in your frontend application, not in Rasa, since it’s just a simple Regex and would be way simpler to implement it there.

Then there, you can send the language as an entity, with every message.

You can first secretely send a payload, e.g. set_language{"English": true} or set_language{"English": false}, to which the bot won’t answer (you just have to not include the set_language intent in a story/rule), and then you directly followup by sending the actual message.


I also just to point out that the way you implemented the logic in your domain is incorrect, or at least can just be optimized.

slots:
  English:
    type: bool
    influence_conversation: False
    mappings:
      - type: from_entity
        entity: English

responses:
  utter_greet:
    - condition:
        - type: slot
          name: English
          value: true
      text: Hey! how i can help you?
    - text: اهلا, عامل ايه
2 Likes

Hello ChrisRahme First: thanks for your fast respond. Second: i have seen your bot, i know it’s speaking 4 different language but it depends on the user selection at the first of the conversation. Third: right now i am creating POC (Proof of concept) for the chat bot but i dont have the ability right now to get the language from the frontend.

the idea now i am trying to implement is to have custom slot which takes any user input and check whether it English or Arabic (but i dont know how i am going to do this).

what i am doing now

 class ActionSetArabic(Action):

    def name(self):
        return "action_set_language"

    def run(self, dispatcher, tracker, domain):
        slot_value = tracker.get_slot('language')
        dispatcher.utter_message(slot_value)
        if slot_value == 'good afternoon':
            lang = 'English'
            return [SlotSet("language", lang)]`
language:
    type: text
    influence_conversation: false
    mappings:
      - type: custom
        action: action_set_language

at first i am trying to prove if i got detect to certain word it going to change the language, but mainly i want to get user input since i cant make entity: language for every example i am going to have.

i have 2 questions: 1- there is anyway to run actions without getting them trigger? 2- how to get the user input and store it ?

Then you have to go with the harder method of creating a Custom Pipeline Component that detects the language.

Can you elaborate? How do you want to run an action without triggering it?

In a Custom Action, you can get the latest user input with tracker.latest_message['text'].

Can you elaborate more about how i can get the result from pipeline component?

and there is no way i can get the user input directly into the slot without making action in a story nor a rule.

from_text slot mapping is your last option.

You need to work if you actually want to get things done.

Since you already have as action as you showed here, why not use tracker.latest_message['text']?

i have used it, but i cant make entity called language and make it in every example, Moreover i need to run the action to get tracker.latest_message['text']and i cant put action “user_input” after every intent in the story.

i am going to send what i have wrote in custom actions but i think solution will be in the custom pipeline, but i hope if there is another simple way.

This is why doing it from the frontend seems the best option for me :slight_smile:

A Custom Pipeline component is the same idea on the backend, but harder.

i want to do it from the fronted but they want they the poc to be from rasa

Then Custom Components are the way to go.

But your supervisors need to be more open-minded. The bot will have an interface eventually.

There are some things you can do in the frontend that are immensely easier to do that in the backend - like letting the bot start the conversation.

i am reading right now the custom components, Here is the custom actions i made

class ActionSetLanguage(Action):

    def name(self):
        return "action_set_language"

    def run(self, dispatcher, tracker, domain):
        sentence = tracker.latest_message['entities'][0]['value']

        # print(tracker.latest_message)
        if sentence == 'hello':
            return [SlotSet("language", "English")]
        elif sentence == 'تمام':
            return [SlotSet("language", None)]
        else:
            return [SlotSet("language", None)]

if you have idea that i could use before i use the custom component it will be good. all i wanted is to get the user input continuously and based on it change the slot language .