public DirectMessage sendDirectMessage(String text) throws TwitterException { return twitter.sendDirectMessage(this.getName(), text); }
@Override public void sendDirectMessage(final Principal principal, final Long toUserId, final String text) throws WTFDYUMException { try { twitter(principal).sendDirectMessage(toUserId, text); } catch (final TwitterException e) { log.debug("Error while sendDirectMessage", e); throw new WTFDYUMException(e, WTFDYUMExceptionType.TWITTER_ERROR); } }
@Override public void invoke(List<TwitterListener> listeners) throws TwitterException { DirectMessage directMessage = twitter.sendDirectMessage(userId, text); for (TwitterListener listener : listeners) { try { listener.sentDirectMessage(directMessage); } catch (Exception e) { logger.warn("Exception at sendDirectMessage", e); } } } });
@Override public void invoke(List<TwitterListener> listeners) throws TwitterException { DirectMessage directMessage = twitter.sendDirectMessage(screenName, text); for (TwitterListener listener : listeners) { try { listener.sentDirectMessage(directMessage); } catch (Exception e) { logger.warn("Exception at sendDirectMessage", e); } } } });
/** * Usage: java twitter4j.examples.DirectMessage senderID senderPassword message recipientId * @param args String[] */ public static void main(String[] args) { if (args.length < 4) { System.out.println("No TwitterID/Password specified."); System.out.println("Usage: java twitter4j.examples.DirectMessage senderID senderPassword message recipientId"); System.exit( -1); } Twitter twitter = new Twitter(args[0], args[1]); try { DirectMessage message = twitter.sendDirectMessage(args[2], args[3]); System.out.println("Direct message successfully sent to " + message.getRecipientScreenName()); System.exit(0); } catch (TwitterException te) { System.out.println("Failed to send message: " + te.getMessage()); System.exit( -1); } } }
public void process(Exchange exchange) throws Exception { // send direct message String toUsername = user; if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(TwitterConstants.TWITTER_USER, String.class))) { toUsername = exchange.getIn().getHeader(TwitterConstants.TWITTER_USER, String.class); } String text = exchange.getIn().getBody(String.class); if (toUsername.isEmpty()) { throw new CamelExchangeException("Username not configured on TwitterEndpoint", exchange); } else { log.debug("Sending to: {} message: {}", toUsername, text); User userStatus = endpoint.getProperties().getTwitter().showUser(toUsername); endpoint.getProperties().getTwitter().sendDirectMessage(userStatus.getId(), text); } }
/** * Sends a new direct message to the specified user from the authenticating user. * Requires both the user and text parameters below. The text will be trimmed if * the length of the text is exceeding 140 characters. * <p/> * {@sample.xml ../../../doc/twitter-connector.xml.sample twitter:sendDirectMessageByUserId} * * @param userId The user ID of the user to whom send the direct message * @param message The text of your direct message * @return the {@link DirectMessage} * @throws TwitterException when Twitter service or network is unavailable */ @Processor public DirectMessage sendDirectMessageByUserId(long userId, String message) throws TwitterException { return getConnectionManagement().getTwitterClient().sendDirectMessage(userId, message); }
/** * Sends a new direct message to the specified user from the authenticating user. * Requires both the user and text parameters below. The text will be trimmed if * the length of the text is exceeding 140 characters. * <p/> * {@sample.xml ../../../doc/twitter-connector.xml.sample twitter:sendDirectMessageByScreenName} * * @param screenName The screen name of the user to whom send the direct message * @param message The text of your direct message * @return the {@link DirectMessage} * @throws TwitterException when Twitter service or network is unavailable */ @Processor public DirectMessage sendDirectMessageByScreenName(String screenName, String message) throws TwitterException { return getConnectionManagement().getTwitterClient().sendDirectMessage(screenName, message); }
/** {@inheritDoc} */ @Override public int send(List<Argument> arguments) { Twitter svc = buildUblogService(arguments); String destUser = findDestName(arguments); DirectMessage response; if (destUser == null || "".equals(destUser)) { LOG.error("Cannot send a microblog DM notice to a user with no microblog username set. Either set a microblog username for this OpenNMS user or use the MicroblogUpdateNotificationStrategy instead."); return 1; } // In case the user tried to be helpful, avoid a double @@ if (destUser.startsWith("@")) destUser = destUser.substring(1); String fullMessage = buildMessageBody(arguments); LOG.debug("Dispatching microblog DM notification at base URL '{}' with destination user '{}' and message '{}'", svc.getConfiguration().getClientURL(), destUser, fullMessage); try { response = svc.sendDirectMessage(destUser, fullMessage); } catch (TwitterException e) { LOG.error("Microblog notification failed at service URL '{}' to destination user '{}'", svc.getConfiguration().getClientURL(), destUser, e); return 1; } LOG.info("Microblog DM notification succeeded: DM sent with ID {}", response.getId()); return 0; } }
public CompletableFuture<DirectMessage> sendMessage(final User recipient, final String content) { LOG.debug("Sending direct message to [{}] with content {}", recipient.getScreenName(), content); return CompletableFuture.supplyAsync(() -> sessionManager.doWithCurrentTwitter( twitter -> twitter.sendDirectMessage(recipient.getId(), content)) ).thenApplyAsync( msgReq -> msgReq.onSuccess(dme -> { LOG.debug("Sent direct message! {}", dme); directMessages.addDirectMessage(dme); }).onFailure( err -> LOG.error("Could not send direct message!", err) ).getOrElseThrow((Function<Throwable, RuntimeException>) RuntimeException::new) ).whenCompleteAsync((res, err) -> { if (err != null) { LOG.error("Could not correctly executed the direct message sending request!", err); } }); }
@Before public void setUp() { try { when(auth.getTwitterService(anyString(), anyString(), anyString(), anyString(), any(boolean.class))).thenReturn(twitter); when(twitter.updateStatus(any(StatusUpdate.class))).thenReturn(status); when(twitter.sendDirectMessage(anyString(), anyString())).thenReturn(directMessage); } catch (Exception e) { fail(e.getMessage()); } }
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) { String message = (String) workItem.getParameter("Message"); String screenName = (String) workItem.getParameter("ScreenName"); // debug is optional (default to false) boolean debugOption = false; if (workItem.getParameter("DebugEnabled") != null) { debugOption = Boolean.parseBoolean((String) workItem.getParameter("DebugEnabled")); } try { RequiredParameterValidator.validate(this.getClass(), workItem); Twitter twitter = auth.getTwitterService(this.consumerKey, this.consumerSecret, this.accessKey, this.accessSecret, debugOption); directMessage = twitter.sendDirectMessage(screenName, message); workItemManager.completeWorkItem(workItem.getId(), null); } catch (Exception e) { handleException(e); } }