# Trigger an intent from the backend with Botfront

**URL:** https://forum.rasa.com/t/trigger-an-intent-from-the-backend-with-botfront/59311
**Category:** Rasa Open Source
**Created:** [August 11, 2023, 7:34am UTC](https://forum.rasa.com/t/trigger-an-intent-from-the-backend-with-botfront/59311 "2023-08-11T07:34:47Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Xiamen](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/xiamen/32/22686_2.png) [@Xiamen](https://forum.rasa.com/u/Xiamen)
#### Post date: [August 11, 2023, 7:34am UTC](https://forum.rasa.com/t/trigger-an-intent-from-the-backend-with-botfront/59311/1 "2023-08-11T07:34:47Z")

</div>

Hi @stephens, I hope you can help with this. I am using botfront to deploy my chatbot. Is there a way to send an intent from the backend via [socket.io](http://socket.io) so that a conversation flow gets triggered and appears on the widget (simulating a user sending message without actually interacting with the botfront widget). I require this because I have different forms that need to be sent out to users on different days and times to record their medication intake.

For example, form A is triggered by intent A at 8pm. When the user access the bot at 9pm they will see the first question of form A and answer it accordingly.

Please if you can offer some assistance with this.

Thank you!

---

<div class="post-metadata">

### Author: ![stephens](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/stephens/32/1632_2.png) [@stephens](https://forum.rasa.com/u/stephens)
#### Post date: [August 11, 2023, 3:08pm UTC](https://forum.rasa.com/t/trigger-an-intent-from-the-backend-with-botfront/59311/2 "2023-08-11T15:08:49Z")

</div>

> I have different forms that need to be sent out to users on different days and times to record their medication intake.

Rasa is not designed for this. You should find a different mechanism to notify the user and push them into a conversation with the bot. Maybe SMS, email, mobile app notification.

> When the user access the bot at 9pm they will see the first question of form A and answer it accordingly.

For this, I would use `action_session_start` which is documented [here](https://rasa.com/docs/rasa/default-actions/#action_session_start). This is automatically called when the user starts a new session and you can kick off a form that checks for any messages that need to be sent or actions/forms that should be started.

---

<div class="post-metadata">

### Author: ![Xiamen](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/xiamen/32/22686_2.png) [@Xiamen](https://forum.rasa.com/u/Xiamen)
#### Post date: [August 11, 2023, 3:16pm UTC](https://forum.rasa.com/t/trigger-an-intent-from-the-backend-with-botfront/59311/3 "2023-08-11T15:16:56Z")

</div>

@stephens thanks for the response, some followup questions.

> Rasa is not designed for this. You should find a different mechanism to notify the user and push them into a conversation with the bot. Maybe SMS, email, mobile app notification.

For example if I send an SMS to the user telling them to log in. Once they are logged in to the portal and have the widget opened, then I have to somehow design a conversation flow where the user has to prompt the form? Is this what you are saying?

> For this, I would use `action_session_start` which is documented [here](https://rasa.com/docs/rasa/default-actions/#action_session_start). This is automatically called when the user starts a new session and you can kick off a form that checks for any messages that need to be sent or actions/forms that should be started.

The issue is I have multiple different forms with different questions. Is it possible to use this function then?

---

<div class="post-metadata">

### Author: ![stephens](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/stephens/32/1632_2.png) [@stephens](https://forum.rasa.com/u/stephens)
#### Post date: [August 14, 2023, 5:20pm UTC](https://forum.rasa.com/t/trigger-an-intent-from-the-backend-with-botfront/59311/4 "2023-08-14T17:20:49Z")

</div>

> For example if I send an SMS to the user telling them to log in. Once they are logged in to the portal and have the widget opened, then I have to somehow design a conversation flow where the user has to prompt the form? Is this what you are saying?

Yes

> The issue is I have multiple different forms with different questions. Is it possible to use this function then?

Yes

---

<div class="post-metadata">

### Author: ![Xiamen](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/xiamen/32/22686_2.png) [@Xiamen](https://forum.rasa.com/u/Xiamen)
#### Post date: [August 14, 2023, 6:27pm UTC](https://forum.rasa.com/t/trigger-an-intent-from-the-backend-with-botfront/59311/5 "2023-08-14T18:27:55Z")

</div>

@stephens sorry one last question, how do i force a form to start upon in the `action_session_start` function? Would it be something like this where we use the ActionExecuted or should it be the FollowUpAction?

```auto

class ActionSessionStart(Action):
    def name(self) -> Text:
        return "action_session_start"

    async def run(
      self, dispatcher, tracker: Tracker, domain: Dict[Text, Any]
    ) -> List[Dict[Text, Any]]:

        # the session should begin with a `session_started` event
        events = [SessionStarted()]

        # force form A to run when Session has started 
        events.append(ActionExecuted("start_formA"))

        # an `action_listen` should be added at the end as a user message follows
        events.append(ActionExecuted("action_listen"))

        return events

```

If this is incorrect, can you please let me know which function I should use?

Thank you in advance.

---

<div class="post-metadata">

### Author: ![stephens](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/stephens/32/1632_2.png) [@stephens](https://forum.rasa.com/u/stephens)
#### Post date: [August 15, 2023, 3:38am UTC](https://forum.rasa.com/t/trigger-an-intent-from-the-backend-with-botfront/59311/6 "2023-08-15T03:38:35Z")

</div>

It’s best to do this with a slot like described [here](https://forum.rasa.com/t/trigger-a-story-or-intent-from-a-custom-action/13784/15) but you can also use FollowUpAction as described [here](https://forum.rasa.com/t/problem-triggering-a-form-from-a-custom-action-in-rasa-3/52294/3).

---

<div class="post-metadata">

### Author: ![Xiamen](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/xiamen/32/22686_2.png) [@Xiamen](https://forum.rasa.com/u/Xiamen)
#### Post date: [August 30, 2023, 4:27pm UTC](https://forum.rasa.com/t/trigger-an-intent-from-the-backend-with-botfront/59311/7 "2023-08-30T16:27:24Z")

</div>

@stephens thank you, i’ll give these option and try. Hopefully that will resolve my issues.
