forked from pimax/fb-messenger-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHandleMessageResponse.php
More file actions
114 lines (99 loc) · 2.86 KB
/
Copy pathHandleMessageResponse.php
File metadata and controls
114 lines (99 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
namespace pimax;
/**
* Class HandleMessageResponse
*
* kapil - 12/07/2016
* @package pimax\Messages
*/
class HandleMessageResponse
{
/**
* @var string
*/
protected $message = null;
/**
* @var string
*/
protected $messageResponse = null;
/**
* default read option
*/
const TYPE_READ = "read";
/**
* Dont read by default option
* readMessageResponse need to be called separately
*/
const TYPE_NOTREAD = "notread";
/**
* HandleMessageResponse constructor.
*
* @param $message
* @param $messageResponse
* @param $readMessage -read message by default or not
*/
public function __construct($message, $messageResponse,$readMessage=self::TYPE_READ)
{
$this->message = $message;
$this->messageResponse = $messageResponse;
if($readMessage===self::TYPE_READ)
$this->readMessageResponse();
}
/**
* Read Message Response returned by fb server
*
*/
public function readMessageResponse()
{
if(isset($this->messageResponse))//safe for null value
{
if(!empty($this->messageResponse['error']))//error occured
$this-> handleError($this->messageResponse['error']);
else //normal response
{
/* parameters present in messageResponse array
* @param recipient_id
* @param message_id
*/
}
}
else
error_log("handleMessageResponse- var messageResponse is null or not defined", 0);
}
/**
* handles error and act accordingly
* @reference- https://developers.facebook.com/docs/messenger-platform/send-api-reference#errors
*/
public function handleError($error)
{
/* parameters available in error array
* @param message -message corresponding to error
* @param code - unique code corresponding to error type
* @param fbtraceid -trace id of error
* @param type - category of error
*/
switch($error['code'])
{case 2: error_log("Send message failure. Internal server error", 0);
//try sending message again
break;
case 4: error_log("Application request limit reached or Too many send requests to phone number", 0);
//cancel the message
break;
case 100: error_log("Invalid fbid. or No matching user found", 0);
//check user id
break;
case 190: error_log("Invalid OAuth access token.", 0);
//check token
break;
case 200: error_log("Permission Errors", 0);
break;
case 551: error_log("User blocked you", 0);
//may delete user data from db
break;
case 10303: error_log("Invalid account_linking_token", 0);
break;
default: error_log("new error may have been introduced consult Send api", 0);
}
}
}
?>