magento live australia 2016 facebook chatbot for magento

32

Click here to load reader

Upload: vrann-tulika

Post on 16-Apr-2017

254 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Magento Live Australia 2016 Facebook Chatbot for Magento
Page 2: Magento Live Australia 2016 Facebook Chatbot for Magento

A Facebook Chat Bot Using Magento 2 Async Processing

Page 3: Magento Live Australia 2016 Facebook Chatbot for Magento

Magento 2 Architect

Eugene Tulika @vrann

Page 4: Magento Live Australia 2016 Facebook Chatbot for Magento

Use-Case: Store With Hand-Picked Books

Page 5: Magento Live Australia 2016 Facebook Chatbot for Magento

Niche Customers With Unusual Requests

Page 6: Magento Live Australia 2016 Facebook Chatbot for Magento

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

Page 7: Magento Live Australia 2016 Facebook Chatbot for Magento

Facebook Chat Bots

• When store Manager cannot handle all communications manually• Facebook webhooks for messages received in the chat• Facebook API for responses

Page 8: Magento Live Australia 2016 Facebook Chatbot for Magento

Facebook POSTs Messages to the Callback

Callback.php200 OK

Page 9: Magento Live Australia 2016 Facebook Chatbot for Magento

Callback POSTs Response to Facebook API

Page 10: Magento Live Australia 2016 Facebook Chatbot for Magento

Understanding the Conversation

Page 11: Magento Live Australia 2016 Facebook Chatbot for Magento

How to Convert Messages to Magento API Requests

Input Classifier

Search catalog by author

Title, image url, description

Page 12: Magento Live Australia 2016 Facebook Chatbot for Magento

Quadrant of Conversation Parsers

Image from https://www.quora.com/What-is-the-best-way-to-learn-and-write-a-AI-Chat-bot

Page 13: Magento Live Australia 2016 Facebook Chatbot for Magento

Wit.AI Retrieval Conversation Setup

Page 14: Magento Live Australia 2016 Facebook Chatbot for Magento

Conversation Parsing

• https://github.com/vrann/phpwit

Do you have a book by Proust?

Intent: catalog_searchParameters: Author: ProustInvoke: catalogSearch(context)

Page 15: Magento Live Australia 2016 Facebook Chatbot for Magento

Integration With Magento

IN/OUT integration Using Web API

Page 16: Magento Live Australia 2016 Facebook Chatbot for Magento

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)

Page 17: Magento Live Australia 2016 Facebook Chatbot for Magento

Callback Makes API Request to Magento

Messenger Callback.php

API

Web API Request

Magento POSTs response to Facebook

Page 18: Magento Live Australia 2016 Facebook Chatbot for Magento

Web API Service Interface

Page 19: Magento Live Australia 2016 Facebook Chatbot for Magento

Magento API Interfaces

• https://github.com/vrann/magebot

Page 20: Magento Live Australia 2016 Facebook Chatbot for Magento

Map Service to the Web API Endpoint

Page 21: Magento Live Australia 2016 Facebook Chatbot for Magento

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!

Page 22: Magento Live Australia 2016 Facebook Chatbot for Magento

API IN Using RabbitMQ

Page 23: Magento Live Australia 2016 Facebook Chatbot for Magento

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

Page 24: Magento Live Australia 2016 Facebook Chatbot for Magento

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):

Page 25: Magento Live Australia 2016 Facebook Chatbot for Magento

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

Page 26: Magento Live Australia 2016 Facebook Chatbot for Magento

API OUT Using RabbitMQ

Page 27: Magento Live Australia 2016 Facebook Chatbot for Magento

Goal: Magento Sends Messages to RabbitMQ

• Scripts: https://github.com/vrann/http-rabbitmq-writer

Messenger

API

callback.php

response.php

Page 28: Magento Live Australia 2016 Facebook Chatbot for Magento

Before: Sender Interface Using HTTP Request

Page 29: Magento Live Australia 2016 Facebook Chatbot for Magento

Now: Sender Interface Using RabbitMQReplace preference for MessageSenderInterface in di.xml, Add “Remote” suffix

Interface implementation will be auto-generated:

Page 30: Magento Live Australia 2016 Facebook Chatbot for Magento

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

Page 31: Magento Live Australia 2016 Facebook Chatbot for Magento

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

Page 32: Magento Live Australia 2016 Facebook Chatbot for Magento

Q&AWrite me @vrann (twitter, github)[email protected]