How to integrate rasa bot with android

Hello, I am trying to integrate rasa-bot with my android app. Are there any options on how to implement it.

kindly suggest.

NOTE: I am not looking for any 3rd party paid chat/voice platforms.

thanks in advance

You would have to build a UI for it, and then connect it to a server running rasa core/nlu somewhere else. The details of this are up to you. You can take a look at how the webchat UI from mr bot is implemented though as an example

Is there any available source code on the web for chat UI in android that might be easily connected to rasa?[quote=“Quresh_Abrar, post:1, topic:2664, full:true”] Hello, I am trying to integrate rasa-bot with my android app. Are there any options on how to implement it.

kindly suggest.

NOTE: I am not looking for any 3rd party paid chat/voice platforms.

thanks in advance [/quote]

@abhishek1 did you find a solution to this?

Hello, there I am Dishant. I have tried to integrate and have created a blog on same please have a look at it and if you have any doubts you can add it in the comment box

“Rasa Chatbot + Android Covid app Tutorial: Part 1” by Dishant gandhi https://link.medium.com/7jH3pLzbvab

1 Like

Hey @Horizon733, You have made nice tutorials on how to integrate rasa chatbot as an Android app, it is really helpful, thank you for your tutorials.

I am not a developer, I am just doing small experiments with these technologies for prototyping purpose. I will be integrating the chatbot in one of my apps and wanted to understand, how I can pass the data of the users(email ID and name) who has logged in to the app to rasa and then call relevant api’s from rasa to perform the requested operations submitted by the user.

Example :

User : Hi

Bot : Greetings

User : I received damaged order

Bot : Sorry to hear that, Ill help you with it. Are you having trouble with the following order?

#Since the user is logged in already, I want to pass his email ID from rasa to its backend, and perform action of fetching his latest order from my api and display the response received from the api as next message.

Can you help me with this, or guide me to a tutorial which resembles similar implementation?

Thank you in advance :slight_smile:

You can automatically and secretly send a payload message from the user on startup with the email and username. For example:

sendMessage(user_id = 1, message = "/give_info{'email': 'user@example.com', 'username': 'User1'}")

In your domain, you should set to autofill the email and username slots, since you’re sending entities with the payload, and you want to save them in slots.


Extra:

In Dishant’s application, if I remember correctly, the ID of the user is always 1 (maybe 0?). This is not recommended for production as everyone will have the same ID. Usually, every user should have a unique ID.

I built a modified version of Dishant’s app here. Is it not complete and still has some bugs, like for the buttons aways appearing on the bottom of the screen. But it generates a random ID when the app is opened instead of always being 1.

Even better than randomly generating the User ID, you could also set it as being the username, so that the database is more organized and doesn’t create a new messenger every time you open the app :slight_smile:

1 Like

Thanks and really glad it helps. To send your data from android to rasa you can add one more key as metadata and then you have to customize your channel file i.e rest.py you can find by clicking here. Also, a beginner tip you should know python and rasa well to start changing channel file as per your need

2 Likes

great work @ChrisRahme I can help you out in android app you build feel free to contact me for that.
I think that force entity extraction doesn’t work everytime. I don’t know why so I suggest to send extras as metadata because it is easy to fetch and can send whatever we want to

1 Like

Thanks @Horizon733! I built the application for my Final Project and I only had a few days. So I don’t think I will develop it further - for now at least.

As for the force entity extraction, I didn’t know it stopped working! That’s weird, it is a very useful feature.

have you tested it recently, the force entity extraction?

1 Like

No I haven’t

Thank you So much @ChrisRahme for the help and the modified version for improved operations. I will give it a try and will share the updates. My apologies for the late response.

1 Like

Hi @Horizon733 , I tried sending the user’s email ID as Chris suggested, but I think I am doing it wrong.

I did the following thing:

  1. I made a static variable with email id private val email_id = "abcd@xyz.com"

In the main app it will be fetched from a the profile data.

  1. In your app example I have set the message to set the email Id in its relevant slot, this is where I am doing it wrong.
fun sendMessage(message: String="/action_receive_email_id{'email_id':'"+email_id+"'}"){
        var userMessage = MessageClass()
        if(message.isEmpty()){
            Toast.makeText(this,"Please type your message",Toast.LENGTH_SHORT).show()
        }
        else{
            userMessage = MessageClass(message,USER)
            messageList.add(userMessage)
            adapter.notifyDataSetChanged()
        }

I have made an action which stores the email ID in email_id slot , when an email ID is entered in rasa shell.

class ActionHelloWorld(Action):

    def name(self) -> Text:

        return "action_receive_email_id"

    def run(self, dispatcher: CollectingDispatcher,

            tracker: Tracker,

            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:

        text = tracker.latest_message['text']

        dispatcher.utter_message(text=f"I'll remember your emial ID {text}")     
        return [SlotSet("email_id", text)]

Can you help me to send private val email_id = "abcd@xyz.com" this email ID to rasa from your app(tutorial) without displaying it in the chat, and setting it as a slot(email_id) value

Thank you

Best 2 ways to do it is as followsđŸ€:

  • try using email as sender id so there is no issue with sending it as message and you know sender id captured and can be used for setting slots
  • Let’s say you don’t want to use it as sender id, send the email as metadata as follows:
{
 "metadata": {
    "email": "email@exmaple.com"
 }
}
1 Like

Thank you so much @Horizon733 for the solution, I would go with option 1. At the Android end, can I define sender_id as email_id in the retrofit = Retrofit.Builder().baseUrl..... section?

no not there but in the UserMessage class, do you remember sender variable there you have to add it

I am sorry I forgot to mention that I had referred to YouTube tutorial( Connecting Rasa Chatbot with App 5 parts), So in that tutorial I think different method is used. I just checked the Covid Chatbot tutorial, and it has the UserMessage class. Ill go through that tutorial and try adding the email to sender variable.

Hey @Horizon733, Thank you so much for the guidance. Quick Update, I used the covidApp tutorial and now I am able to pass my desired value as sender_id. Now I am working on setting sender_id as a slot, hoping to find a documentation or a tutorial :sweat_smile:

yes, building a good one for the community with new tools and something else, can’t reveal right now😊