Yam Code
Sign up
Login
New paste
Home
Trending
Archive
English
English
Tiếng Việt
भारत
Sign up
Login
New Paste
Browse
<?php /** * Copyright 2017 Juno_okyo <junookyo@gmail.com> * * Website: https://junookyo.blogspot.com/ */ namespace juno_okyo; class Chatfuel { const VERSION = '1.0.0'; protected $response = array(); public function __construct($debug = FALSE) { if (( ! $debug) && ( ! isset($_SERVER['HTTP_USER_AGENT']) OR strpos($_SERVER['HTTP_USER_AGENT'], 'Apache-HttpAsyncClient') === FALSE)) { exit; } } public function __destruct() { if (count($this->response) > 0) { try { header('Content-Type: application/json'); echo json_encode(array('messages' => $this->response)); exit; } catch (Exception $e) { // noop } } } public function sendText($messages = null) { if (is_null($messages)) { throw new Exception('Invalid input', 1); } $type = gettype($messages); if ($type === 'string') { $this->response[] = array('text' => $messages); } elseif ($type === 'array' || is_array($messages)) { foreach ($messages as $message) { $this->response[] = array('text' => $message); } } else { $this->response[] = array('text' => 'Error!'); } } public function sendImage($url) { if ($this->isURL($url)) { $this->sendAttachment('image', array('url' => $url)); } else { $this->sendText('Error: Invalid URL!'); } } public function sendVideo($url) { if ($this->isURL($url)) { $this->sendAttachment('video', array('url' => $url)); } else { $this->sendText('Error: Invalid URL!'); } } public function sendAudio($url) { if ($this->isURL($url)) { $this->sendAttachment('audio', array('url' => $url)); } else { $this->sendText('Error: Invalid URL!'); } } public function sendTextCard($text, $buttons) { if (is_array($buttons)) { $this->sendAttachment('template', array( 'template_type' => 'button', 'text' => $text, 'buttons' => $buttons )); return TRUE; } return FALSE; } public function sendGallery($elements) { if (is_array($elements)) { $this->sendAttachment('template', array( 'template_type' => 'generic', 'elements' => $elements )); return TRUE; } return FALSE; } public function createElement($title, $image, $subTitle, $buttons) { if ($this->isURL($image) && is_array($buttons)) { return array( 'title' => $title, 'image_url' => $image, 'subtitle' => $subTitle, 'buttons' => $buttons ); } return FALSE; } public function createButtonToBlock($title, $block, $setAttributes = NULL) { $button = array(); $button['type'] = 'show_block'; $button['title'] = $title; if (is_array($block)) { $button['block_names'] = $block; } else { $button['block_name'] = $block; } if ( ! is_null($setAttributes) && is_array($setAttributes)) { $button['set_attributes'] = $setAttributes; } return $button; } public function createButtonToURL($title, $url, $setAttributes = NULL) { if ($this->isURL($url)) { $button = array(); $button['type'] = 'web_url'; $button['url'] = $url; $button['title'] = $title; if ( ! is_null($setAttributes) && is_array($setAttributes)) { $button['set_attributes'] = $setAttributes; } return $button; } return FALSE; } public function createPostBackButton($title, $url) { if ($this->isURL($url)) { return array( 'url' => $url, 'type' => 'json_plugin_url', 'title' => $title ); } return FALSE; } public function createCallButton($phoneNumber, $title = 'Call') { return array( 'type' => 'phone_number', 'phone_number' => $phoneNumber, 'title' => $title ); } public function createShareButton() { return array('type' => 'element_share'); } public function createQuickReply($text, $quickReplies) { if (is_array($quickReplies)) { $this->response['text'] = $text; $this->response['quick_replies'] = $quickReplies; return TRUE; } return FALSE; } public function createQuickReplyButton($title, $block) { $button = array(); $button['title'] = $title; if (is_array($block)) { $button['block_names'] = $block; } else { $button['block_name'] = $block; } return $button; } private function sendAttachment($type, $payload) { $type = strtolower($type); $validTypes = array('image', 'video', 'audio', 'template'); if (in_array($type, $validTypes)) { $this->response[] = array( 'attachment' => array( 'type' => $type, 'payload' => $payload ) ); } else { $this->response[] = array('text' => 'Error: Invalid type!'); } } private function isURL($url) { return filter_var($url, FILTER_VALIDATE_URL); } }
Paste Settings
Paste Title :
[Optional]
Paste Folder :
[Optional]
Select
Syntax Highlighting :
[Optional]
Select
Markup
CSS
JavaScript
Bash
C
C#
C++
Java
JSON
Lua
Plaintext
C-like
ABAP
ActionScript
Ada
Apache Configuration
APL
AppleScript
Arduino
ARFF
AsciiDoc
6502 Assembly
ASP.NET (C#)
AutoHotKey
AutoIt
Basic
Batch
Bison
Brainfuck
Bro
CoffeeScript
Clojure
Crystal
Content-Security-Policy
CSS Extras
D
Dart
Diff
Django/Jinja2
Docker
Eiffel
Elixir
Elm
ERB
Erlang
F#
Flow
Fortran
GEDCOM
Gherkin
Git
GLSL
GameMaker Language
Go
GraphQL
Groovy
Haml
Handlebars
Haskell
Haxe
HTTP
HTTP Public-Key-Pins
HTTP Strict-Transport-Security
IchigoJam
Icon
Inform 7
INI
IO
J
Jolie
Julia
Keyman
Kotlin
LaTeX
Less
Liquid
Lisp
LiveScript
LOLCODE
Makefile
Markdown
Markup templating
MATLAB
MEL
Mizar
Monkey
N4JS
NASM
nginx
Nim
Nix
NSIS
Objective-C
OCaml
OpenCL
Oz
PARI/GP
Parser
Pascal
Perl
PHP
PHP Extras
PL/SQL
PowerShell
Processing
Prolog
.properties
Protocol Buffers
Pug
Puppet
Pure
Python
Q (kdb+ database)
Qore
R
React JSX
React TSX
Ren'py
Reason
reST (reStructuredText)
Rip
Roboconf
Ruby
Rust
SAS
Sass (Sass)
Sass (Scss)
Scala
Scheme
Smalltalk
Smarty
SQL
Soy (Closure Template)
Stylus
Swift
TAP
Tcl
Textile
Template Toolkit 2
Twig
TypeScript
VB.Net
Velocity
Verilog
VHDL
vim
Visual Basic
WebAssembly
Wiki markup
Xeora
Xojo (REALbasic)
XQuery
YAML
HTML
Paste Expiration :
[Optional]
Never
Self Destroy
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Status :
[Optional]
Public
Unlisted
Private (members only)
Password :
[Optional]
Description:
[Optional]
Tags:
[Optional]
Encrypt Paste
(
?
)
Create New Paste
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Site Languages
×
English
Tiếng Việt
भारत