-
Notifications
You must be signed in to change notification settings - Fork 31
Send API
Romain Monteil edited this page Sep 21, 2018
·
11 revisions
- Send a simple message
- Send an action
- Send a message with quick replies
- Send a message with buttons
- Send a message with a receipt
- Send a message with an Airline Boarding Pass
- Send a message with an Airline Checkin
- Send a message with an Airline Itinerary
$messenger->send()->message(<USER_ID>, 'Hello world!');
$messenger->send()->action(<USER_ID>, Send::SENDER_ACTION_TYPING_ON);
use Kerox\Messenger\Model\Message;
use Kerox\Messenger\Model\Message\QuickReply;
$message = new Message('Pick a color:');
$message
->setQuickReplies([
QuickReply::create(QuickReply::CONTENT_TYPE_TEXT)
->setTitle('Red')
->setPayload('DEVELOPER_DEFINED_PAYLOAD_FOR_PICKING_RED')
->setImageUrl('http://petersfantastichats.com/img/red.png'),
QuickReply::create(QuickReply::CONTENT_TYPE_TEXT)
->setTitle('Green')
->setPayload('DEVELOPER_DEFINED_PAYLOAD_FOR_PICKING_GREEN')
->setImageUrl('http://petersfantastichats.com/img/green.png')
])
->addQuickReply(QuickReply::create(QuickReply::CONTENT_TYPE_LOCATION))
->setMetadata('some metadata');
$messenger->send()->message(<USER_ID>, $message);
use Kerox\Messenger\Model\Common\Button\PhoneNumber;
use Kerox\Messenger\Model\Common\Button\Postback;
use Kerox\Messenger\Model\Common\Button\WebUrl;
use Kerox\Messenger\Model\Message\Attachment\Template\ButtonTemplate;
$buttons = ButtonTemplate::create('Hello World', [
PhoneNumber::create('Contact Info', 'CONTACT_INFO_PAYLOAD'),
Postback::create('Pay Bill', 'PAYBILL_PAYLOAD'),
WebUrl::create('Example', 'http://example.com'),
]);
$messenger->send()->message(<USER_ID>, $buttons);
use Kerox\Messenger\Api\Send;
use Kerox\Messenger\Model\Common\Address;
use Kerox\Messenger\Model\Message\Attachment\Template\Element\ReceiptElement;
use Kerox\Messenger\Model\Message\Attachment\Template\Receipt\Adjustment;
use Kerox\Messenger\Model\Message\Attachment\Template\Receipt\Summary;
use Kerox\Messenger\Model\Message\Attachment\Template\ReceiptTemplate;
$elements = [
ReceiptElement::create('Classic White T-Shirt', 50)
->setSubtitle('100% Soft and Luxurious Cotton')
->setQuantity(2)
->setCurrency('USD')
->setImageUrl('http://petersapparel.parseapp.com/img/whiteshirt.png'),
ReceiptElement::create('Classic Gray T-Shirt', 25))
->setSubtitle('100% Soft and Luxurious Cotton')
->setQuantity(1)
->setCurrency('USD')
->setImageUrl('http://petersapparel.parseapp.com/img/grayshirt.png'),
];
$summary = Summary::create(56.14)
->setSubtotal(75.00)
->setShippingCost(4.95)
->setTotalTax(6.19);
$receipt = ReceiptTemplate::create('Stephane Crozatier', '12345678902', 'USD', 'Visa 2345', $elements, $summary);
->setTimestamp('1428444852')
->setOrderUrl('http://petersapparel.parseapp.com/order?order_id=123456')
->setAddress(Address::create('1 Hacker Way', 'Menlo Park', '94025', 'CA', 'US'))
->setAdjustments([
Adjustment::create()->setName('New Customer Discount')->setAmount(20),
Adjustment::create()->setName('$10 Off Coupon')->setAmount(10),
]);
$messenger->send()->message(<USER_ID>, $receipt, [
'messaging_type' => SendInterface::MESSAGING_TYPE_RESPONSE,
'notification_type' => SendInterface::NOTIFICATION_TYPE_REGULAR,
'tag' => SendInterface::TAG_ACCOUNT_UPDATE
]);
use Kerox\Messenger\Model\Message\Attachment\Template\Airline\Airport;
use Kerox\Messenger\Model\Message\Attachment\Template\Airline\BoardingPass;
use Kerox\Messenger\Model\Message\Attachment\Template\Airline\FlightInfo;
use Kerox\Messenger\Model\Message\Attachment\Template\Airline\FlightSchedule;
use Kerox\Messenger\Model\Message\Attachment\Template\AirlineBoardingPassTemplate;
$departureAirport = Airport::create('JFK', 'New York')
->setTerminal('T1')
->setGate('D57');
$arrivalAirport = Airport::create('AMS', 'Amsterdam');
$flightSchedule = FlightSchedule::create('2016-01-02T19:05')
->setArrivalTime('2016-01-05T17:30');
$flightInfo = FlightInfo::create('KL0642', $departureAirport, $arrivalAirport, $flightSchedule);
$boardingPass1 = BoardingPass::create('Smith Nicolas', 'CG4X7U', 'https://www.example.com/en/logo.png', 'M1SMITH NICOLAS CG4X7U nawouehgawgnapwi3jfa0wfh', 'https://www.example.com/en/PLAT.png', $flightInfo)
->setTravelClass('business')
->setSeat('74J')
->addAuxiliaryFields('Terminal', 'T1')
->addAuxiliaryFields('Departure', '30OCT 19:05')
->addSecondaryFields('Boarding', '18:30')
->addSecondaryFields('Gate', 'D57')
->addSecondaryFields('Seat', '74J')
->addSecondaryFields('Sec.Nr.', '003')
->setHeaderImageUrl('https://www.example.com/en/fb/header.png');
$boardingPass2 = BoardingPass::create('Jones Farbound', 'CG4X7U', 'https://www.example.com/en/logo.png', 'M1JONES FARBOUND CG4X7U nawouehgawgnapwi3jfa0wfh', 'https://www.example.com/en/PLAT.png', $flightInfo)
->setTravelClass('business')
->setSeat('74K')
->addAuxiliaryFields('Terminal', 'T1')
->addAuxiliaryFields('Departure', '30OCT 19:05')
->addSecondaryFields('Boarding', '18:30')
->addSecondaryFields('Gate', 'D57')
->addSecondaryFields('Seat', '74K')
->addSecondaryFields('Sec.Nr.', '004')
->setHeaderImageUrl('https://www.example.com/en/fb/header.png');
$boardingPass = [
$boardingPass1,
$boardingPass2,
];
$airlineBoardingPass = AirlineBoardingPassTemplate::create('You are checked in.', 'en_US', $boardingPass)
->setThemeColor('#FF0000');
$messenger->send()->message(<USER_ID>, $airlineBoardingPass);
use Kerox\Messenger\Model\Message\Attachment\Template\Airline\Airport;
use Kerox\Messenger\Model\Message\Attachment\Template\Airline\FlightInfo;
use Kerox\Messenger\Model\Message\Attachment\Template\Airline\FlightSchedule;
use Kerox\Messenger\Model\Message\Attachment\Template\AirlineCheckInTemplate;
$departureAirport = Airport::create('SFO', 'San Francisco')
->setTerminal('T4')
->setGate('G8');
$arrivalAirport = Airport::create('SEA', 'Seattle')
->setTerminal('T4')
->setGate('G8');
$flightSchedule = FlightSchedule::create('2016-01-05T15:45')
->setArrivalTime('2016-01-05T17:30')
->setBoardingTime('2016-01-05T15:05');
$flightInto = [
FlightInfo::create('f001', $departureAirport, $arrivalAirport, $flightSchedule)
];
$airlineCheckIn = AirlineCheckInTemplate::create('Check-in is available now.', 'en_US', 'ABCDEF', $flightInto, 'https://www.airline.com/check-in');
$messenger->send()->message(<USER_ID>, $airlineCheckIn);
use Kerox\Messenger\Model\Message\Attachment\Template\Airline\Airport;
use Kerox\Messenger\Model\Message\Attachment\Template\Airline\ExtendedFlightInfo;
use Kerox\Messenger\Model\Message\Attachment\Template\Airline\FlightInfo;
use Kerox\Messenger\Model\Message\Attachment\Template\Airline\FlightSchedule;
use Kerox\Messenger\Model\Message\Attachment\Template\Airline\PassengerInfo;
use Kerox\Messenger\Model\Message\Attachment\Template\Airline\PassengerSegmentInfo;
use Kerox\Messenger\Model\Message\Attachment\Template\AirlineItineraryTemplate;
$departureAirport1 = Airport::create('SFO', 'San Francisco')
->setTerminal('T4')
->setGate('G8');
$departureAirport2 = Airport::create('SLC', 'Salt Lake City')
->setTerminal('T1')
->setGate('G33');
$arrivalAirport1 = Airport::create('SLC', 'Salt Lake City')
->setTerminal('T4')
->setGate('G8');
$arrivalAirport2 = Airport::create('AMS', 'Amsterdam')
->setTerminal('T1')
->setGate('G33');
$flightSchedule1 = FlightSchedule::create('2016-01-02T19:45')
->setArrivalTime('2016-01-02T21:20');
$flightSchedule2 = FlightSchedule::create('2016-01-02T22:45')
->setArrivalTime('2016-01-03T17:20');
$passengerInfo = [
PassengerInfo::create('p001', 'Farbound Smith Jr')
->setTicketNumber('0741234567890'),
PassengerInfo::create('p002', 'Nick Jones')
->setTicketNumber('0741234567891'),
];
$flightInfo = [
ExtendedFlightInfo::create('c001', 's001', 'KL9123', $departureAirport1, $arrivalAirport1, $flightSchedule1, TravelClassInterface::BUSINESS)
->setAircraftType('Boeing 737'),
ExtendedFlightInfo::create('c002', 's002', 'KL321', $departureAirport2, $arrivalAirport2, $flightSchedule2, TravelClassInterface::BUSINESS)
->setAircraftType('Boeing 747-200'),
];
$passengerSegmentInfo = [
PassengerSegmentInfo::create('s001', 'p001', '12A', 'Business'),
PassengerSegmentInfo::create('s001', 'p002', '12B', 'Business'),
PassengerSegmentInfo::create('s002', 'p001', '73A', 'World Business')
->addProductInfo('Lounge', 'Complimentary lounge access')
->addProductInfo('Baggage', '1 extra bag 50lbs'),
PassengerSegmentInfo::create('s002', 'p002', '73B', 'World Business')
->addProductInfo('Lounge', 'Complimentary lounge access')
->addProductInfo('Baggage', '1 extra bag 50lbs'),
];
$airlineItinerary = AirlineItineraryTemplate::create('Here\'s your flight itinerary.', 'en_US', 'ABCDEF', $passengerInfo, $flightInfo, $passengerSegmentInfo, '14003', 'USD');
$airlineItinerary
->addPriceInfo('Fuel surcharge', '1597', 'USD')
->setBasePrice('12206')
->setTax('200');
$messenger->send()->message(<USER_ID>, $airlineItinerary);