Skip to content

Commit 7ed0ef9

Browse files
committed
add readme
1 parent 50bf130 commit 7ed0ef9

3 files changed

Lines changed: 167 additions & 102 deletions

File tree

Messenger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public function EntryID() {
178178
return $this->data["entry"][0]["id"];
179179
}
180180

181-
private function sendAPIRequest($url, array $content, $post = true, $response = false) {
181+
private function sendAPIRequest($url, array $content, $post = true, $response = true) {
182182
$ch = curl_init($url);
183183
if ($post) {
184184
curl_setopt($ch, CURLOPT_POST, 1);

README.md

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,62 @@
1-
# MessengerBotPHP
1+
# MessengerBotPHP
2+
> A very simple PHP [Messenger Bot API](https://developers.facebook.com/docs/messenger-platform) for sending messages.
3+
> Based on [Telegram Bot API](https://core.telegram.org/bots) by [Eleirbag89](https://github.com/Eleirbag89).
4+
5+
Requirements
6+
---------
7+
8+
* PHP5
9+
* Curl for PHP5 must be enabled.
10+
* Create a Facebook App at [https://developers.facebook.com/apps/](https://developers.facebook.com/apps/)
11+
12+
For the WebHook:
13+
* 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.
14+
15+
Installation
16+
---------
17+
18+
* Copy Messenger.php into your server and include it in your new bot script
19+
```php
20+
include("Messenger.php");
21+
$facebook = new Messenger($bot_id);
22+
```
23+
24+
Configuration (WebHook)
25+
---------
26+
27+
Navigate to [https://developers.facebook.com/apps/YOUR_APP_ID/messenger/](https://developers.facebook.com/apps/YOUR_APP_ID/messenger/) and add the webhook.
28+
29+
Examples
30+
---------
31+
32+
```php
33+
$facebook = new Messenger($bot_id);
34+
$text = $facebook->Text();
35+
$chat_id = $facebook->ChatID();
36+
$message_id = $facebook->EntryID();
37+
$message = "Hello World";
38+
$result = $facebook->sendMessage($chat_id, $message);
39+
```
40+
41+
See examples.php for the complete example.
42+
43+
Emoticons
44+
------------
45+
For a list of emoticons to use in your bot messages, please refer to the column Bytes of this table:
46+
http://apps.timwhitlock.info/emoji/tables/unicode
47+
48+
F.A.Q.
49+
------------
50+
**Q: Can you implement <???> function?**
51+
52+
A: I can try. Open a issue and I'll see what I can do.
53+
54+
**Q: Your code is awesome. How can I help?**
55+
56+
A: Thank you! You can help by codding more features, creating pull requests, or donating using Bitcoin: **1BdL9w4SscX21b2qeiP1ApAFNAYhPj5GgG**
57+
58+
License
59+
------------
60+
Free. Don't forget to star :D and send pull requests. :D
61+
62+
**Free Software, Hell Yeah!**

examples.php

Lines changed: 104 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -11,107 +11,111 @@
1111
$message_id = $facebook->EntryID();
1212

1313
$message = "";
14+
$result = "";
1415

15-
if ($text == "text") // simple text message
16+
if(!is_null($text) && !is_null($chat_id))
1617
{
17-
$message = "Hello World";
18-
$facebook->sendMessage($chat_id, $message);
19-
}
20-
else if ($text == "button") // buttons
21-
{
22-
$message = "Hello World";
23-
$button = array(
24-
array(
25-
'type' => 'web_url',
26-
'url' => 'https://google.com',
27-
'title' => 'Button 1'
28-
),
29-
array(
30-
'type' => 'web_url',
31-
'url' => 'https://google.com',
32-
'title' => 'Button 2'
33-
),
34-
array(
35-
'type' => 'web_url',
36-
'url' => 'https://google.com',
37-
'title' => 'Button 3'
38-
)
39-
);
40-
$facebook->sendButtonTemplate($chat_id, $message, $button);
41-
}
42-
else if ($text == "replies") // quick replies
43-
{
44-
$message = "Pick one";
45-
$replies = array(
46-
array(
47-
'content_type' => 'text',
48-
'title' => 'Option One',
49-
'payload' => 'PAYLOAD_ONE'
50-
),
51-
array(
52-
'content_type' => 'text',
53-
'title' => 'Option Two',
54-
'payload' => 'PAYLOAD_TWO'
55-
),
56-
array(
57-
'content_type' => 'text',
58-
'title' => 'Option Three',
59-
'payload' => 'PAYLOAD_THREE'
60-
)
61-
);
62-
$facebook->sendQuickReply($chat_id, $message, $replies);
63-
}
64-
if ($text == "generic") // generic template
65-
{
66-
$button = array(
67-
array(
68-
'type' => 'web_url',
69-
'url' => 'https://google.com',
70-
'title' => 'Button One'
71-
),
72-
array(
73-
'type' => 'web_url',
74-
'url' => 'https://google.com',
75-
'title' => 'Button Two'
76-
)
77-
);
78-
$elements = array(
79-
array(
80-
'title' => 'Title One',
81-
'item_url' => 'https://google.com',
82-
'image_url' => 'http://placehold.it/350x350',
83-
'subtitle' => 'Item Description Here',
84-
'buttons' => $button
85-
),
86-
array(
87-
'title' => 'Title Two',
88-
'item_url' => 'https://google.com',
89-
'image_url' => 'http://placehold.it/350x350',
90-
'subtitle' => 'Item Description Here',
91-
'buttons' => $button
92-
),
93-
array(
94-
'title' => 'Title Three',
95-
'item_url' => 'https://google.com',
96-
'image_url' => 'http://placehold.it/350x350',
97-
'subtitle' => 'Item Description Here',
98-
'buttons' => $button
99-
),
100-
array(
101-
'title' => 'Title Four',
102-
'item_url' => 'https://google.com',
103-
'image_url' => 'http://placehold.it/350x350',
104-
'subtitle' => 'Item Description Here',
105-
'buttons' => $button
106-
),
107-
array(
108-
'title' => 'Title Five',
109-
'item_url' => 'https://google.com',
110-
'image_url' => 'http://placehold.it/350x350',
111-
'subtitle' => 'Item Description Here',
112-
'buttons' => $button
113-
)
114-
);
115-
$a = $facebook->sendGenericTemplate($chat_id, $elements);
18+
if ($text == "text") // simple text message
19+
{
20+
$message = "Hello World";
21+
$result = $facebook->sendMessage($chat_id, $message);
22+
}
23+
else if ($text == "button") // buttons
24+
{
25+
$message = "Hello World";
26+
$button = array(
27+
array(
28+
'type' => 'web_url',
29+
'url' => 'https://google.com',
30+
'title' => 'Button 1'
31+
),
32+
array(
33+
'type' => 'web_url',
34+
'url' => 'https://google.com',
35+
'title' => 'Button 2'
36+
),
37+
array(
38+
'type' => 'web_url',
39+
'url' => 'https://google.com',
40+
'title' => 'Button 3'
41+
)
42+
);
43+
$result = $facebook->sendButtonTemplate($chat_id, $message, $button);
44+
}
45+
else if ($text == "replies") // quick replies
46+
{
47+
$message = "Pick one";
48+
$replies = array(
49+
array(
50+
'content_type' => 'text',
51+
'title' => 'Option One',
52+
'payload' => 'PAYLOAD_ONE'
53+
),
54+
array(
55+
'content_type' => 'text',
56+
'title' => 'Option Two',
57+
'payload' => 'PAYLOAD_TWO'
58+
),
59+
array(
60+
'content_type' => 'text',
61+
'title' => 'Option Three',
62+
'payload' => 'PAYLOAD_THREE'
63+
)
64+
);
65+
$result = $facebook->sendQuickReply($chat_id, $message, $replies);
66+
}
67+
else if ($text == "generic") // generic template
68+
{
69+
$button = array(
70+
array(
71+
'type' => 'web_url',
72+
'url' => 'https://google.com',
73+
'title' => 'Button One'
74+
),
75+
array(
76+
'type' => 'web_url',
77+
'url' => 'https://google.com',
78+
'title' => 'Button Two'
79+
)
80+
);
81+
$elements = array(
82+
array(
83+
'title' => 'Title One',
84+
'item_url' => 'https://google.com',
85+
'image_url' => 'http://placehold.it/350x350',
86+
'subtitle' => 'Item Description Here',
87+
'buttons' => $button
88+
),
89+
array(
90+
'title' => 'Title Two',
91+
'item_url' => 'https://google.com',
92+
'image_url' => 'http://placehold.it/350x350',
93+
'subtitle' => 'Item Description Here',
94+
'buttons' => $button
95+
),
96+
array(
97+
'title' => 'Title Three',
98+
'item_url' => 'https://google.com',
99+
'image_url' => 'http://placehold.it/350x350',
100+
'subtitle' => 'Item Description Here',
101+
'buttons' => $button
102+
),
103+
array(
104+
'title' => 'Title Four',
105+
'item_url' => 'https://google.com',
106+
'image_url' => 'http://placehold.it/350x350',
107+
'subtitle' => 'Item Description Here',
108+
'buttons' => $button
109+
),
110+
array(
111+
'title' => 'Title Five',
112+
'item_url' => 'https://google.com',
113+
'image_url' => 'http://placehold.it/350x350',
114+
'subtitle' => 'Item Description Here',
115+
'buttons' => $button
116+
)
117+
);
118+
$result = $facebook->sendGenericTemplate($chat_id, $elements);
119+
}
116120
}
117121
?>

0 commit comments

Comments
 (0)