Home

Awesome

Features

Requirements

Changes

To manage instagram and whatsapp they both has to be matched to you page

Permissions we request from facebook during login

Default scopes. You can change those in settings/settings.ini.php file

'email','pages_show_list','pages_messaging','instagram_manage_messages',
'instagram_basic','pages_manage_metadata','pages_read_engagement',
'whatsapp_business_management','whatsapp_business_messaging','business_management'

Webhook configuration and subscription fields

Webhooks configuration place

See image

Products you should have

See image

Facebook messenger

In webhooks page you have to choose Page and subscribe to those fields

Subscribed fields - message_deliveries,message_echoes,message_edits,message_reactions,message_reads,messages,messaging_postbacks

Instagram

In webhooks page you have to choose Instagram and subscribe to those fields

Subscribed fields - messages,messages,messaging_postbacks,messaging_seen

WhatsApp

In webhooks page you have to choose Whatsapp Business Account and subscribe to those fields

Subscribed fields - messages

Most common URL

URL if you are using Facebook Login flow without automated hosting environment

This is the most common installation method and you choose what page you managed during login flow.

Webhook URL's. Use same URL for webhook verification calls.

Valid OAuth Redirect URIs

Webhook URL for facebook messenger if you define independent page

You create a facebook app and add pages manually to lhc back office without login flow.

URL if you are using Facebook Login flow with automated hosting environment

Valid OAuth Redirect URIs. master.example.com in this scenario is our manager address

Webhook URL's. Use same URL for webhook verification calls.

Facebook messenger extension

Integration with Facebook messenger API. You will be able to chat with Facebook page users directly in lhc back office.

Update instructions

Installation in your LHC server

'extensions' =>  array (  'fbmessenger',  ),

WhatsApp configuration

Notice - WhatsApp campaigns etc are supported only for statically defined WhatsApp accounts. Login based WhatsApp phone numbers for campaigns will be added later.

This configuration option is available with Permanent Access Token. In facebook Extension settings you have to enter

Few documentation links in Meta platform

!fbtemplate {"template_name":"hello_world","template_lang":"en_us","args":{}}
!fbtemplate {"template_name":"quick_reply","template_lang":"en","args":{"field_1":"name","field_header_1":"header"}}

See image

From WhatsApp perspective we support images, text, video, audio, contact, location, sticker, document messages types

To send campaign of template messages this cronjob has to be setup.

How to listen for quick reply actions from templates you send?

Each quick reply button send from lhc get's payload constructed as.

$item->template.'-quick_reply_'.$indexButton, => quick_reply-quick_reply_0

This is needed because we don't have chat upfront and can't set payload upfront.

So just listen for Custom text matching with that keyword. This sample is provided in bot sample

I have bot for default department, but I want chat go directly to pending state if I send a template?

You have few options

Important

Gotchas

Cronjobs

This cronjob sends scheduled campaign messages and regular mass messages Should be run every minute or more frequent.

php cron.php -s site_admin -e fbmessenger -c cron/masssending

Collects campaign recipients and puts them in the main mass messages queue. Should be run every minute or more frequent.

php cron.php -s site_admin -e fbmessenger -c cron/whatsapp_campaign

One page one app installation workflow

This method is usefull if you are planning to use this extension by creating separate apps for each page you manage.

Actions to do in developers.facebook.com and Live Helper Chat back office

So at the end everything should look like

See image

See image

One account multiple page installation workflow

This workflow is usefull if you are planning to use more than one page per facebook account.

One app multiple servers installation

This scenario is usefull in case you have multiple clients and each client has it's own server or address. You can have one master instance which will act as Master and will forward all incoming request from facebook to correct URL of child server.

To activate that option you have to edit extension/fbmessenger/settings/settings.ini.php and set options similar to below

'standalone' => array (
        'enabled' => true,
        'secret_hash' => 'random_string_to_out',
        'address' => 'https://mater.example.com' // Master instance address
    ),

In facebook Valid OAuth Redirect URIs has to be changed to E.g

https://mater.example.com/site_admin/fbmessenger/fbcallbackstandalone

Messenger -> Settings Webhooks Callback URL has to be set to

https://mater.example.com/fbmessenger/callbackstandalone

Then Submit to facebook to validate your app

Finally Make your app public.

How it works

Once visitor writes a message in facebook page. You will receive a chat with visitor.

How to debug

in extension/fbmessenger/settings/settings.ini.php change setting to 'enable_debug' => true if you have verified site. Check cache/default.log for more detailed error.

How to grant permission to other facebook user to your page so he can subscribe to messenger

How to install extensions using DigitalOcean?

Execute these commands

/opt/livehelperchat/lhc_upgrade.sh
cd /var/www/git
git clone https://github.com/LiveHelperChat/fbmessenger.git
cd /var/www/git/fbmessenger
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php
php -r "unlink('composer-setup.php');"
./composer.phar install
cd /var/www/html/extension
ln -s /var/www/git/fbmessenger
cp /var/www/html/extension/fbmessenger/settings/settings.ini.default.php /var/www/html/extension/fbmessenger/settings/settings.ini.php 
php cron.php -s site_admin -e fbmessenger -c cron/update_structure

If you are using instance as standalone copy all content from master instance /var/www/html/extension/fbmessenger/settings/settings.ini.php

Activate extension by editing

vi /var/www/html/settings/settings.ini.php

And make extensions section look like

'extensions' => 
  array (
	0 => 'nodejshelper',
	1 => 'lhcphpresque',
	2 => 'fbmessenger',
  ),

Setup cronjob to renew SSL automatically

crontab -e

And add this line

0 */12 * * * /usr/bin/certbot renew --post-hook "systemctl reload nginx" >> /var/log/le-renew.log

Todo