Skip to content

Send API

Romain Monteil edited this page Mar 19, 2017 · 11 revisions

Send API

Send a simple message:

$messenger->send()->message(<USER_ID>, 'Hello world!');

Send a message with quick replies:

use Kerox\Messenger\Model\Message;
use Kerox\Messenger\Model\Message\QuickReply;

$message = new Message('Pick a color:');
$message
    ->setQuickReplies([
        (new QuickReply('text'))
            ->setTitle('Red')
            ->setPayload('DEVELOPER_DEFINED_PAYLOAD_FOR_PICKING_RED')
            ->setImageUrl('http://petersfantastichats.com/img/red.png'),
        (new QuickReply('text'))
            ->setTitle('Green')
            ->setPayload('DEVELOPER_DEFINED_PAYLOAD_FOR_PICKING_GREEN')
            ->setImageUrl('http://petersfantastichats.com/img/green.png')
    ])
    ->addQuickReply(new QuickReply('location'))
    ->setMetadata('some metadata');
    
$messenger->send()->message(<USER_ID>, $message);

Send a message with a receipt

use Kerox\Messenger\Model\Common\Address;
use Kerox\Messenger\Model\Message\Attachment\Template\Element\ReceiptElement;
use Kerox\Messenger\Model\Message\Attachment\Template\Receipt;
use Kerox\Messenger\Model\Message\Attachment\Template\Receipt\Adjustment;
use Kerox\Messenger\Model\Message\Attachment\Template\Receipt\Summary;

$elements = [
    (new ReceiptElement('Classic White T-Shirt', 50))->setSubtitle('100% Soft and Luxurious Cotton')->setQuantity(2)->setCurrency('USD')->setImageUrl('http://petersapparel.parseapp.com/img/whiteshirt.png'),
    (new ReceiptElement('Classic Gray T-Shirt', 25))->setSubtitle('100% Soft and Luxurious Cotton')->setQuantity(1)->setCurrency('USD')->setImageUrl('http://petersapparel.parseapp.com/img/grayshirt.png'),
];

$summary = new Summary(56.14);
$summary
    ->setSubtotal(75.00)
    ->setShippingCost(4.95)
    ->setTotalTax(6.19);

$receipt = new Receipt('Stephane Crozatier', '12345678902', 'USD', 'Visa 2345', $elements, $summary);
$receipt
    ->setTimestamp('1428444852')
    ->setOrderUrl('http://petersapparel.parseapp.com/order?order_id=123456')
    ->setAddress(new Address('1 Hacker Way', 'Menlo Park', '94025', 'CA', 'US'))
    ->setAdjustments([
        (new Adjustment())->setName('New Customer Discount')->setAmount(20),
        (new Adjustment())->setName('$10 Off Coupon')->setAmount(10),
    ]);
            
$messenger->send()->message(<USER_ID>, $receipt);
Clone this wiki locally