Receiving and Processing Messages Sent on Twitter
Function
This interface is invoked to receive and process messages sent on Twitter.
Usage Description
Prerequisites
response_token for authentication has been successfully generated by invoking the interface in Calling Back Data on Twitter.
Interface Authentication
Obtain the authentication character string from the request header x-twitter-webhooks-signature and delete sha256= from the character string.
Obtain the value of appSecret configured for the channel, encrypt the request and appSecret in the request using SHA256, and generate an authentication character string for comparison.
String signatureHeader = request.getHeader("x-twitter-webhooks-signature");
String payloadContent = IOUtils.toString(request.getReader());
String signature = StringUtils.substringAfter(signatureHeader, "sha256=");
try {
String payloadHash = BaseUtil.hMacSha256(payloadContent, consumerKey);
if (!StringUtils.equals(signature, payloadHash)) {
log.error("The signature is not correct, channelId = {}", channelId);
return false;
}
} catch (NoSuchAlgorithmException | InvalidKeyException e) {
log.error("get payloadHash failed", e);
return false;
}
Interface Prototype
|
Method |
POST |
|
|---|---|---|
|
URL |
https://{IP address}:{Port number}/social/on/twitter/{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 |
Default Value |
Description |
|---|---|---|---|---|
|
Content-Type |
Yes |
String |
None |
The value is fixed at application/x-www-form-urlencoded. |
|
x-twitter-webhooks-signature |
Yes |
String |
None |
This parameter is used to authenticate the MO message interface and is generated by invoking the interface in Calling Back Data on Twitter. |
|
Parameter |
Mandatory or Not |
Type |
Default Value |
Description |
|---|---|---|---|---|
|
direct_message_events |
Yes |
JSON array |
None |
Event data. For details, see Table 4. |
|
users |
Yes |
String |
None |
User data. For details, see Table 6. |
|
Parameter |
Mandatory or Not |
Type |
Default Value |
Description |
|---|---|---|---|---|
|
message_create |
Yes |
JSON object |
None |
Message sent by a user. For details, see Table 5. |
|
created_timestamp |
Yes |
String |
None |
Timestamp when a message is sent. |
Response Parameters
If this interface is invoked successfully, no response is returned.
Example
- Request
POST x-twitter-webhooks-signature: xxxxxxxxxxxxxxx /************************* Accept: */* Host: 10.154.198.164 Content-Type: application/x-www-form-urlencoded { "direct_message_events" : [ "message_create" : { "sender_id" : "01122552341412", "message_id" : "aaaswfwefew1255" }, "created_timestamp" : "1111235235666" ], "user" : { "id" : "01122552341412", "name" : "sgyyub", "profile_image_url_https" : "https://www.twitter/xxxxxx" } }
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