magento live australia 2016 facebook chatbot for magento
Post on 16-Apr-2017
254 Views
Preview:
TRANSCRIPT
A Facebook Chat Bot Using Magento 2 Async Processing
Magento 2 Architect
Eugene Tulika @vrann
Use-Case: Store With Hand-Picked Books
Niche Customers With Unusual Requests
Facebook Page
• Facebook is the best way to reach larger and targeted audience• Facebook Page representing the store• Customers don’t want to leave Facebook to shop in store• Customers ask questions in Messenger
Facebook Chat Bots
• When store Manager cannot handle all communications manually• Facebook webhooks for messages received in the chat• Facebook API for responses
Facebook POSTs Messages to the Callback
Callback.php200 OK
Callback POSTs Response to Facebook API
Understanding the Conversation
How to Convert Messages to Magento API Requests
Input Classifier
Search catalog by author
Title, image url, description
Quadrant of Conversation Parsers
Image from https://www.quora.com/What-is-the-best-way-to-learn-and-write-a-AI-Chat-bot
Wit.AI Retrieval Conversation Setup
Conversation Parsing
• https://github.com/vrann/phpwit
Do you have a book by Proust?
Intent: catalog_searchParameters: Author: ProustInvoke: catalogSearch(context)
Integration With Magento
IN/OUT integration Using Web API
On average, Magento store has integrations with 15 different external systems
Integrations Framework:• API In supported by Web API (CE) and RabbitMQ (EE)• API Out supported by RabbitMQ (EE)
Callback Makes API Request to Magento
Messenger Callback.php
API
Web API Request
Magento POSTs response to Facebook
Web API Service Interface
Map Service to the Web API Endpoint
What Can Go Wrong?
When customer writes in Messenger:• Blocking request from callback to Magento• Scalability: Magento can be overloaded processing other requests• Availability: Magento API is unreachable at that moment
Messages from customer can be lost!
API IN Using RabbitMQ
Callback Puts Messages to the Queue
• Scripts: https://github.com/vrann/http-rabbitmq-writer
Messenger
API
Callback.php
Magento POSTs response to Facebook
Rabbit MQ
Transformation of Web API to Inbound Calls via RabbitMQ
Map message handler to topic in communication.xml
Map consumer to queue in queue_consumer.xml
Run consumer(s):
Communication & Queue Configurations
We achieved: Non-Blocking request, response to Facebook sent immediately Scalability handled by Queue Availability handled by QueueCommunication vs Queue:• Communication Framework is an abstraction around
publisher/subscriber. It can be implemented:– with database and HTTP requests instead (webhooks)– in-memory (observers)
• Queue is a Transport layer for Communication– configuration of RabbitMQ adapter and topology
API OUT Using RabbitMQ
Goal: Magento Sends Messages to RabbitMQ
• Scripts: https://github.com/vrann/http-rabbitmq-writer
Messenger
API
callback.php
response.php
Before: Sender Interface Using HTTP Request
Now: Sender Interface Using RabbitMQReplace preference for MessageSenderInterface in di.xml, Add “Remote” suffix
Interface implementation will be auto-generated:
Publisher & Topology
queue_publisher.xml maps generated topic to the exchange
queue_topology.xml configures exchange to queue bindings
• Prior to Magento EE 2.2 these config are in queue.xml
Wrap Up
• We covered:– Reasons behind Magento Web API data structures– Reasons to use queues– Switch from Web API to the RabbitMQ – Code generation of API OUT for RabbitMQ– Communication framework vs Queue framework– Separation of publishers, consumers, topology in 2.2– Input Message Handling– Facebook bots!
• https://github.com/vrann/facebook-chatbot• https://github.com/vrann/http-rabbitmq-writer• https://github.com/vrann/magebot
Q&AWrite me @vrann (twitter, github)etulika@magento.com
top related