Skip to main content

Create a Machinat App

Let's create our first app and run it up! In this lesson, we'll create a hello-world chatbot and make it available on the chat platform.

Time to accomplish: 15 minutes

Chat Platform

Machinat now supports three chat platforms: messenger, telegram and line. Pick one platform to use in the lessons and run this command in the terminal:

npm init @machinat/app@latest -- -p <platform> --webview my-todo-bot

The command initiates a new project of a hello-world bot. Try cd my-todo-bot and take a look.

tip

To support multiple chat platforms, add more -p <platform> flag.

Platform Setup

Before starting the app, you need to set up the chat platform first. Please follow the guide of the platform you choose:

Create a Facebook app

  1. Visit https://developers.facebook.com/apps, tap Create App to create a new app.
  2. Go to: App Dashboard > Settings > Basic.
  3. Copy the value of App ID and App Secret. Paste them in the .env file in the project. Like:
MESSENGER_APP_ID= 1234567890
MESSENGER_APP_SECRET= abcdef123456...

Use Messenger in you app

Go to: App Dashboard > Add a Product > Messenger > Set Up

Create a Facebook page if you don't have one:

Go to: Messenger Setting > Access Tokens > Create New Page. Then follow the instructions to create a page.

Connect your page to the app

  1. Go to: Messenger Setting > Access Tokens > Add or Remove Pages.
  2. Choose the page you just created. After confirmation, you page should be listed in the Access Tokens area.
  3. Copy the id of the page and paste it in the .env file, like:
MESSENGER_PAGE_ID= 1234567890

Get page token

Press Generate Token at the connected page. Copy the generated token and paste it in the .env file, like:

MESSENGER_ACCESS_TOKEN= AaBbCcDdEeFf123456...

Start App

Start Dev Server

Now run this command in the project directory:

npm run dev

Your app should be successfully running if all the required settings are filled.

Run Migrations

There is one more step for the first time starting. Keep the dev server running, and execute this command in another command line tab:

npm run migrate

The command registers some necessary settings to the Messenger platform. Now try messaging your Facebook page, the app should work like this:


Our first bot is running! Next, you'll learn how to receive messages and make the reply.