# How to Use GotoFlow?

> A possible solution is to make use of the gotoFlow to be able to divert the logic depending on the response of the http request to be able to verify if the user is registered in the database or is a new user. registered...
>
> - **Canonical URL:** https://www.builderbot.app/en/showcases/gotoflow-use
> - **Documentation Index:** https://www.builderbot.app/llms.txt
> - **Full Corpus:** https://www.builderbot.app/llms-full.txt

## Issue 
I needed to be able to detect users that were already registered in my system so I need to make a get http query to my external system to check if that number was registered or not and depending on that divert it to a convenient flow.

---

## Possible Solution 

A possible solution is to make use of the gotoFlow to be able to divert the logic depending on the response of the http request to be able to verify if the user is registered in the database or is a new user.
registered in the database or is a new user.

```ts (app.ts)
import { createBot, createProvider, createFlow, addKeyword, MemoryDB, EVENTS } from "@builderbot/bot";
import { BaileysProvider } from "@builderbot/provider-baileys";
import registeredUsersFlow from "./flows/registeredUsersFlow";
import unregisteredUsersFlow from "./flows/unregisteredUsersFlow";

const welcomeFlow = addKeyword(EVENTS.WELCOME).addAction(
  async (_, { gotoFlow, state }) => {
    const checkDB = await fetch("http://my.app.example/checkDB", {
      method: "POST",
      body: JSON.stringify({ phoneNumber: state.from }),
      headers: {
        "Content-Type": "application/json",
      },
    });

    const status = await checkDB.json();
    if (status === undefined) {
      await state.update({ Registration: false });
      return gotoFlow(unregisteredUsersFlow);
    }
    if (status === true) {
      return gotoFlow(registeredUsersFlow);
    }
  }
);

const main = async () => {
  const provider = createProvider(BaileysProvider);
  const database = new MemoryDB();
  const flow = createFlow([welcomeFlow, registeredUsersFlow, unregisteredUsersFlow]);

  await createBot({ flow, provider, database });
};

main();
```
```ts (unregisteredUsersFlow.ts)
import { EVENTS, addKeyword } from "@bot-whatsapp/bot";
import registeredUsersFlow from "./registeredUsersFlow";

const unregisteredUsersFlow = addKeyword(EVENTS.ACTION).addAnswer(
  "To register, I need your full name. Please enter your full name.",
  { capture: true },
  async (ctx, { state, flowDynamic, gotoFlow }) => {
    const { body } = ctx;
    await state.update({ Registration: true, Name: body });
    await flowDynamic(`You have been successfully registered.`);
    return gotoFlow(registeredUsersFlow);
  }
);

export default unregisteredUsersFlow;
```

```ts (registeredUsersFlow.ts)
import { EVENTS, addKeyword } from "@bot-whatsapp/bot";
// Flow of registered users
const registeredUsersFlow = addKeyword(EVENTS.ACTION).addAction(
  { delay: 3000 },
  async (_, { state, flowDynamic }) => {
    const name = await state.get("Name");
    await flowDynamic(`Hello ${name}! How can I help you?`);
    return;
  }
);

export default registeredUsersFlow;
```

---
