Skip to content

Commit

Permalink
add readme
Browse files Browse the repository at this point in the history
  • Loading branch information
blopa committed Feb 18, 2017
1 parent 50bf130 commit 7ed0ef9
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 102 deletions.
2 changes: 1 addition & 1 deletion Messenger.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public function EntryID() {
return $this->data["entry"][0]["id"];
}

private function sendAPIRequest($url, array $content, $post = true, $response = false) {
private function sendAPIRequest($url, array $content, $post = true, $response = true) {
$ch = curl_init($url);
if ($post) {
curl_setopt($ch, CURLOPT_POST, 1);
Expand Down
63 changes: 62 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,62 @@
# MessengerBotPHP
# MessengerBotPHP
> A very simple PHP [Messenger Bot API](https://developers.facebook.com/docs/messenger-platform) for sending messages.
> Based on [Telegram Bot API](https://core.telegram.org/bots) by [Eleirbag89](https://github.com/Eleirbag89).
Requirements
---------

* PHP5
* Curl for PHP5 must be enabled.
* Create a Facebook App at [https://developers.facebook.com/apps/](https://developers.facebook.com/apps/)

For the WebHook:
* An SSL certificate (Telegram API requires this). You can use [Cloudflare's Free Flexible SSL](https://www.cloudflare.com/ssl) which crypts the web traffic from end user to their proxies if you're using CloudFlare DNS.

Installation
---------

* Copy Messenger.php into your server and include it in your new bot script
```php
include("Messenger.php");
$facebook = new Messenger($bot_id);
```

Configuration (WebHook)
---------

Navigate to [https://developers.facebook.com/apps/YOUR_APP_ID/messenger/](https://developers.facebook.com/apps/YOUR_APP_ID/messenger/) and add the webhook.

Examples
---------

```php
$facebook = new Messenger($bot_id);
$text = $facebook->Text();
$chat_id = $facebook->ChatID();
$message_id = $facebook->EntryID();
$message = "Hello World";
$result = $facebook->sendMessage($chat_id, $message);
```

See examples.php for the complete example.

Emoticons
------------
For a list of emoticons to use in your bot messages, please refer to the column Bytes of this table:
http://apps.timwhitlock.info/emoji/tables/unicode

F.A.Q.
------------
**Q: Can you implement <???> function?**

A: I can try. Open a issue and I'll see what I can do.

**Q: Your code is awesome. How can I help?**

A: Thank you! You can help by codding more features, creating pull requests, or donating using Bitcoin: **1BdL9w4SscX21b2qeiP1ApAFNAYhPj5GgG**

License
------------
Free. Don't forget to star :D and send pull requests. :D

**Free Software, Hell Yeah!**
204 changes: 104 additions & 100 deletions examples.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,107 +11,111 @@
$message_id = $facebook->EntryID();

$message = "";
$result = "";

if ($text == "text") // simple text message
if(!is_null($text) && !is_null($chat_id))
{
$message = "Hello World";
$facebook->sendMessage($chat_id, $message);
}
else if ($text == "button") // buttons
{
$message = "Hello World";
$button = array(
array(
'type' => 'web_url',
'url' => 'https://google.com',
'title' => 'Button 1'
),
array(
'type' => 'web_url',
'url' => 'https://google.com',
'title' => 'Button 2'
),
array(
'type' => 'web_url',
'url' => 'https://google.com',
'title' => 'Button 3'
)
);
$facebook->sendButtonTemplate($chat_id, $message, $button);
}
else if ($text == "replies") // quick replies
{
$message = "Pick one";
$replies = array(
array(
'content_type' => 'text',
'title' => 'Option One',
'payload' => 'PAYLOAD_ONE'
),
array(
'content_type' => 'text',
'title' => 'Option Two',
'payload' => 'PAYLOAD_TWO'
),
array(
'content_type' => 'text',
'title' => 'Option Three',
'payload' => 'PAYLOAD_THREE'
)
);
$facebook->sendQuickReply($chat_id, $message, $replies);
}
if ($text == "generic") // generic template
{
$button = array(
array(
'type' => 'web_url',
'url' => 'https://google.com',
'title' => 'Button One'
),
array(
'type' => 'web_url',
'url' => 'https://google.com',
'title' => 'Button Two'
)
);
$elements = array(
array(
'title' => 'Title One',
'item_url' => 'https://google.com',
'image_url' => 'http://placehold.it/350x350',
'subtitle' => 'Item Description Here',
'buttons' => $button
),
array(
'title' => 'Title Two',
'item_url' => 'https://google.com',
'image_url' => 'http://placehold.it/350x350',
'subtitle' => 'Item Description Here',
'buttons' => $button
),
array(
'title' => 'Title Three',
'item_url' => 'https://google.com',
'image_url' => 'http://placehold.it/350x350',
'subtitle' => 'Item Description Here',
'buttons' => $button
),
array(
'title' => 'Title Four',
'item_url' => 'https://google.com',
'image_url' => 'http://placehold.it/350x350',
'subtitle' => 'Item Description Here',
'buttons' => $button
),
array(
'title' => 'Title Five',
'item_url' => 'https://google.com',
'image_url' => 'http://placehold.it/350x350',
'subtitle' => 'Item Description Here',
'buttons' => $button
)
);
$a = $facebook->sendGenericTemplate($chat_id, $elements);
if ($text == "text") // simple text message
{
$message = "Hello World";
$result = $facebook->sendMessage($chat_id, $message);
}
else if ($text == "button") // buttons
{
$message = "Hello World";
$button = array(
array(
'type' => 'web_url',
'url' => 'https://google.com',
'title' => 'Button 1'
),
array(
'type' => 'web_url',
'url' => 'https://google.com',
'title' => 'Button 2'
),
array(
'type' => 'web_url',
'url' => 'https://google.com',
'title' => 'Button 3'
)
);
$result = $facebook->sendButtonTemplate($chat_id, $message, $button);
}
else if ($text == "replies") // quick replies
{
$message = "Pick one";
$replies = array(
array(
'content_type' => 'text',
'title' => 'Option One',
'payload' => 'PAYLOAD_ONE'
),
array(
'content_type' => 'text',
'title' => 'Option Two',
'payload' => 'PAYLOAD_TWO'
),
array(
'content_type' => 'text',
'title' => 'Option Three',
'payload' => 'PAYLOAD_THREE'
)
);
$result = $facebook->sendQuickReply($chat_id, $message, $replies);
}
else if ($text == "generic") // generic template
{
$button = array(
array(
'type' => 'web_url',
'url' => 'https://google.com',
'title' => 'Button One'
),
array(
'type' => 'web_url',
'url' => 'https://google.com',
'title' => 'Button Two'
)
);
$elements = array(
array(
'title' => 'Title One',
'item_url' => 'https://google.com',
'image_url' => 'http://placehold.it/350x350',
'subtitle' => 'Item Description Here',
'buttons' => $button
),
array(
'title' => 'Title Two',
'item_url' => 'https://google.com',
'image_url' => 'http://placehold.it/350x350',
'subtitle' => 'Item Description Here',
'buttons' => $button
),
array(
'title' => 'Title Three',
'item_url' => 'https://google.com',
'image_url' => 'http://placehold.it/350x350',
'subtitle' => 'Item Description Here',
'buttons' => $button
),
array(
'title' => 'Title Four',
'item_url' => 'https://google.com',
'image_url' => 'http://placehold.it/350x350',
'subtitle' => 'Item Description Here',
'buttons' => $button
),
array(
'title' => 'Title Five',
'item_url' => 'https://google.com',
'image_url' => 'http://placehold.it/350x350',
'subtitle' => 'Item Description Here',
'buttons' => $button
)
);
$result = $facebook->sendGenericTemplate($chat_id, $elements);
}
}
?>

0 comments on commit 7ed0ef9

Please sign in to comment.