Receiving and Processing MO Messages Sent on Facebook
Function
This interface is invoked to receive and process MO messages sent on Facebook.
Usage Description
Interface Authentication
Obtain the authentication character string in the request header X-Hub-Signature-XX and compare the parameter in the request with the encrypted secretKey in the channel configuration. If they are the same, the authentication is successful.
String algorithm = channelConfig.getAlgorithm();
String signature = "";
if (AlgorithmEnum.SHA256.getValue().equals(algorithm)) {
String signatureHeader = request.getHeader("X-Hub-Signature-256");
// Verify signatureHeaderSha256.
if (StringUtils.isTrimEmpty(signatureHeader)) {
log.error("sha256 Signature from facebook is empty");
return false;
}
signature = StringUtils.substringAfter(signatureHeader, "sha256=");
} else {
String signatureHeader = request.getHeader();
// Verify signatureHeader.
if (StringUtils.isTrimEmpty(signatureHeader)) {
log.error("sha1 Signature from facebook is empty");
return false;
}
signature = StringUtils.substringAfter(signatureHeader, "sha1=");
}
String hash;
try {
hash = getSignatureByAlgorithm(payloadContent, secretKey, channelConfig.getAlgorithm());
} catch (Exception e) {
log.error("Fail to get the signature, and the exception is {}", e.getMessage());
return false;
}
return StringUtils.equals(hash, signature);
The SHA1 encryption algorithm has security risks. Exercise caution when using this algorithm.
Interface Prototype
|
Method |
POST |
|
|---|---|---|
|
URL |
https://{IP address}:{Port number}/social/on/facebook/{channelId} |
{IP address}:{Port number} indicates the IP address and port number of the NSLB exposed externally. {channelId} indicates the channel ID. |
Request Parameters
|
Parameter |
Mandatory or Not |
Type |
Description |
|---|---|---|---|
|
Content-Type |
Yes |
String |
The value is fixed at application/json; charset=UTF-8. |
|
X-Hub-Signature-XX |
Yes |
String |
Facebook authentication information. |
|
Parameter |
Mandatory or Not |
Type |
Description |
|---|---|---|---|
|
object |
Yes |
String |
Request object structure. |
|
entry |
Yes |
JSON array |
entry contains event data. For details, see Table 4. |
|
Parameter |
Mandatory or Not |
Type |
Description |
|---|---|---|---|
|
id |
Yes |
String |
Home page ID. |
|
time |
Yes |
Long |
Request time. |
|
messaging |
Yes |
JSON array |
Messaging webhook event. For details, see Table 5. |
|
Parameter |
Mandatory or Not |
Type |
Description |
|---|---|---|---|
|
message |
Yes |
JSON object |
Event content. For details, see Table 6. |
|
sender |
Yes |
JSON object |
Sender ID, in the format of {"id":"5465176836886605"}. |
|
timestamp |
Yes |
Long |
Time when a message is sent. |
|
recipient |
Yes |
JSON object |
The value is in the format of {"id":"107416531546370"}. |
Response Parameters
If this interface is invoked successfully, no response is returned.
If this interface fails to be invoked, a status code and error description are returned.
Example
- Request
POST /social/on/facebook/202108135240338790 host : 10.10.10.2:28090 connection : Keep-Alive x-forwarded-for : 10.10.10.3, 10.10.10.4 x-real-ip : 10.10.10.5 content-length : 314 remote-host : 10.10.10.6 accept : */* accept-encoding : deflate, gzip user-agent : facebookexternalua content-type : application/json x-hub-signature-256 : sha256=599c****************3bc facebook-api-version : v8.0 { "object" : "page", "entry" : [{ "id" : "107416531546370", "time" : 1629191082254, "messaging" : [{ "sender" : { "id" : "5465176836886605" }, "recipient" : { "id" : "107416531546370" }, "timestamp" : 1629191082001, "message" : { "mid" : "m_5ugOgGm2v5x36EyvvInnNOwvV5bGYdVdhgz8VK0mdjnLC3qm8PfaQZdWwAsLOg8hiDIqmpkcYQtllLH_tDzl7A", "text" : "jianlian" } } ] } ] }
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot