From 4b33a4d4fabe0c76eedf77d90e88c4dae1735a8b Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Fri, 10 Dec 2010 16:20:28 -0500 Subject: [PATCH] INT-1636 updated Twitter documentation regarding 'target-user-expression' --- docs/src/reference/docbook/twitter.xml | 46 +++++++++++++++---- .../DirectMessageSendingMessageHandler.java | 4 +- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/docs/src/reference/docbook/twitter.xml b/docs/src/reference/docbook/twitter.xml index 55dfd9bd42..4460b25d62 100644 --- a/docs/src/reference/docbook/twitter.xml +++ b/docs/src/reference/docbook/twitter.xml @@ -160,7 +160,9 @@ received. Inbound Message Channel Adapter This adapter allows you to receive updates from everyone you follow. It's essentially the "Timeline Update" adapter. - + ]]> @@ -170,7 +172,9 @@ received. Direct Inbound Message Channel Adapter This adapter allows you to receive Direct Messages that were sent to you from other Twitter users. - + ]]> @@ -180,8 +184,9 @@ received. Mentions Inbound Message Channel Adapter This adapter allows you to receive Twitter Messages that Mention you via @user syntax. - + ]]> @@ -192,8 +197,9 @@ received. This adapter allows you to perform searches. As you can see it is not necessary to define twitter-template since a search can be performed anonymously, however you must define a search query. - + ]]> @@ -234,7 +240,9 @@ received. This adapter allows you to send regular status updates by simply sending a Message to the channel identified by the channel attribute. - ]]> + ]]> The only extra configuration that is required for this adapter is the twitter-template reference. @@ -244,9 +252,31 @@ received. This adapter allows you to send Direct Twitter Messages (i.e., @user) by simply sending a Message to the channel identified by the channel attribute. - ]]> + ]]> The only extra configuration that is required for this adapter is the twitter-template reference. + + When it comes to Twitter Direct Message you must specify who you sending this message to - target userid. + Twitter Outbound Direct Message Channel Adapter provides several ways you can specify target user. + By default it will look for target userid in the Message headers under the name twitter_dmTargetUserId which + is also identified by the following constant - TwitterHeaders.DM_TARGET_USER_ID. + So when creating a Message all you need to do is add this header: + + + + + The above approach works well if you know the target userid in advance. However there are times when such + value must be determined dynamically. For those cases you can utilize SpEL support by providing valid SpEL + expression via target-user-expression attribute. + + ]]> + Twitter does not allow you to post duplicate Messages. This is a common problem during testing when diff --git a/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/outbound/DirectMessageSendingMessageHandler.java b/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/outbound/DirectMessageSendingMessageHandler.java index 62ac5fc98c..4d5cb4caf7 100644 --- a/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/outbound/DirectMessageSendingMessageHandler.java +++ b/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/outbound/DirectMessageSendingMessageHandler.java @@ -60,9 +60,7 @@ public class DirectMessageSendingMessageHandler extends AbstractMessageHandler { protected void handleMessageInternal(Message message) throws Exception { Assert.isInstanceOf(String.class, message.getPayload(), "Only payload of type String is supported. If your payload " + "is not of type String consider adding a transformer to the message flow in front of this adapter."); -// Assert.isTrue(message.getHeaders().containsKey(TwitterHeaders.DM_TARGET_USER_ID), -// "the '" + TwitterHeaders.DM_TARGET_USER_ID + "' header is required"); - + Object toUser = targetUserExpression.getValue(this.evaluationContext, message); Assert.isTrue(toUser instanceof String || toUser instanceof Integer,