Download the PHP package donmarkus/chatbot without Composer

On this page you can find all versions of the php package donmarkus/chatbot. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package chatbot

Chatbot PHP Boilerplate

This package makes it simple to start building a chatbot in PHP.

Software License GitHub version


If you want to start building a chatbot in PHP, then this boilerplate is a perfect start. It includes everything you need to know to connect you application to a messenger platform. You will find simple examples to reply to chat messages. (Currently only Facebook Messenger is supported)

Additionally this boilerplate supports bot platforms like api.ai and wit.ai too. This will help you to process and understand the user's intent.

This package uses PSR-1 and PSR-2, If you notice compliance oversights, please send a patch via pull request.

Requirements

Supported messenger platform

Covered

Not covered

Installation

Create a FB page

First login to Facebook and create a Facebook page. The page doesn't need to be public. Choose the settings that fits best your bot, but for testing it is not important.

Create a FB Messenger app

Go to the developer's app page. Click "Add a New App" and fill the basic app fields.

Image of Facebook app creation

On the "Product Setup" page choose Messenger and click "Get Started".

Image of the app product setup

Now we need to create a token to give our app access to our Facebook page. Select the created page, grant permissions and copy the generated token. We need that one later.

Image of the token creation

Setup the Chatbot PHP Boilerplate

First clone the repository and remove the existing git folder.

Now we need to install the Composer dependencies:

This boilerplate is working with an .env file (environment). All sensible data like keys are stored there. This file should be listed in your .gitignore file. This is because this data should not be included in your repository. Additionally you are able to use different keys on different environments. (e.g. test bot platform account on your local environment)

In this boilerplate there is an example file included called .env.example. Rename it in order to use it.

Next take a look at this file. Here we have two values to consider for now. First one is the WEBHOOK_VERIFY_TOKEN which is a token you can define yourself here. Fill something in now, we will need it later. The second value ist the PAGE_ACCESS_TOKEN which we already got from our messenger app. Fill it in here. Perfect!

Create a webhook for the messenger app

On our PHP application we need to have a webhook. This means a public URL that Facebook can talk to. Every time the user writes a message inside the FB chat, FB will send it to this URL which is the entrance point to our PHP application. In this boilerplate it is the index.php file.

So we need a public URL to the index.php file and there are two options here for you.

Make it live (Standalone)

If you got a server you can push your code there where you have public access to it. The URL then maybe looks like https://yourserver.com/chatbot/examples/index.php.

Do it locally

For testing it is definitely easier when you don't have to push every change to a live server in order to test the code. This is why I use a local public URL. There are multiple services out there that generate a public URL to your local server. Checkout out ngrok or use Laravel Valet Sharing which is my choice since I'm using Valet already. (Laravel Valet is using ngrok under the hood too)

It doesn't matter how you do it, but you just need a public secured URL to the index.php file. (https!). This is my URL: https://7def2gH4.ngrok.io/examples/index.php

Connect the Facebook app to your application

Now that we got the URL we need to setup the webhook. Go back to you Facebook app settings and click Setup Webhooks inside the Webhooks part.

Image of Facebook app webhook setup

Fill in in the public URL, the WEBHOOK_VERIFY_TOKEN from the .env file, check all the subscription fields and click Verify and Save.

Image of Facebook app webhook infos

If you did everything right you have a working webhook now. If not you will see an error icon at the webhook URL field. This happens if the URL or the token is not correct.

Connect the Facebook app to the Facebook page

Now the last step of the installation will make sure that our Facebook app is connected to the Facebook page. For this purpose there is a dropdown within your Webhooks setting page. Choose you page here and click Subscribe.

Image of Facebook app webhook select page to subscribe to

Test it

So finally we can test the whole setup. Go to you Facebook page and click the message button in order to send a message. Type Hi and press enter. You should now see this answer: Define your own logic to reply to this message: Hi

Image showing your first chatbot response

If you see this, then congratulations. You did it! You have successfully installed the Chatbot PHP Boilerplate and received your first reply.

If you don't get a reply, then something went wrong =( Check your server's log files to find out more. Additionally you can use the built in Monolog Logger to debug the applications.

Usage

Example 1: Static message

In your index.php file you will find this line of code:

Here the user's message is being used to get an answer. In this case the message is analysed in the ChatbotAi method getAnswer. It is simply returning a static text with the original message. Like mentioned below, you can define your own logic to respond to the message. It is also common to use PHP's preg_match function to look for words inside the message. In the example the method return some hello text, if the message contains hi , hey or hello.

Example 2: Foreign Exchange Rates

Here a public API is used to return foreign exchange rates to the user. The user can type currencies like EUR, USD, CHF etc. It is a simple example but good to see how to work with external APIs.

Image showing the rates example

Example 3: Using bot platforms

Bot platforms can help you analyse the user's intent of a message. Currently only api.ai and (wit .ai are supported.

API.ai

To use api.ai you just need to add the parameter apiapi to the getAnswer method. There is also an example in your index.php file.

Wit.ai

To use wit.ai you just need to add the parameter witai to the getAnswer method. There is also an example in your index.php file.

Wit.ai will analyze the users's message. This example implementation will just send back the user's intent.

Full example examples/index.php

Image showing the response with wit.ai

Of course you need to add a story to you Wit.ai application like:

Image showing the story of wit.ai

Included Packages

Special Thanks To :

License

The MIT License (MIT).


All versions of chatbot with dependencies

PHP Build Version
Package Version
Requires php Version >=7.0
iboldurev/api-ai-php Version ^0.2.5
monolog/monolog Version ^1.22
vlucas/phpdotenv Version ^2.4
tgallice/wit-php Version ^0.3.1
pimax/fb-messenger-php Version ^1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package donmarkus/chatbot contains the following files

Loading the files please wait ....