private void onDestinationReceived(Message message, String language) { String origin = DatabaseManager.getInstance().getUserOrigin(message.getFrom().getId()); String destiny = message.getText(); List<String> directions = DirectionsService.getInstance().getDirections(origin, destiny, language); SendMessage sendMessageRequest = new SendMessage(); sendMessageRequest.setChatId(message.getChatId().toString()); ReplyKeyboardHide replyKeyboardHide = new ReplyKeyboardHide(); replyKeyboardHide.setSelective(true); sendMessageRequest.setReplayMarkup(replyKeyboardHide); sendMessageRequest.setReplayToMessageId(message.getMessageId()); Message sentMessage = null; for (String direction : directions) { sendMessageRequest.setText(direction); SenderHelper.SendApiMethodAsync( sendMessageRequest, TOKEN, new SentCallback<Message>() { @Override public void onResult(BotApiMethod<Message> method, JSONObject jsonObject) { Message sentMessage = method.deserializeResponse(jsonObject); if (sentMessage != null) { DatabaseManager.getInstance().deleteUserForDirections(message.getFrom().getId()); } } @Override public void onError(BotApiMethod<Message> method, JSONObject jsonObject) {} }); } }
private void onStartdirectionsCommand(Message message, String language) { SendMessage sendMessageRequest = new SendMessage(); sendMessageRequest.setChatId(message.getChatId().toString()); sendMessageRequest.setReplayToMessageId(message.getMessageId()); ForceReplyKeyboard forceReplyKeyboard = new ForceReplyKeyboard(); forceReplyKeyboard.setSelective(true); sendMessageRequest.setReplayMarkup(forceReplyKeyboard); sendMessageRequest.setText( LocalisationService.getInstance().getString("initDirections", language)); SenderHelper.SendApiMethodAsync( sendMessageRequest, TOKEN, new SentCallback<Message>() { @Override public void onResult(BotApiMethod<Message> method, JSONObject jsonObject) { Message sentMessage = method.deserializeResponse(jsonObject); if (sentMessage != null) { DatabaseManager.getInstance() .addUserForDirection( message.getFrom().getId(), WATING_ORIGIN_STATUS, sentMessage.getMessageId(), null); } } @Override public void onError(BotApiMethod<Message> method, JSONObject jsonObject) {} }); }
static void validateRequiredMessagePropertiesArePresent(Message message) { if (message.getMessageId() == null) { throw new MessageFormatException( Message.MESSAGE_ID_HEADER_NAME + " is missing but is a required message header."); } if (message.getMessageTimestamp() == null) { throw new MessageFormatException( Message.MESSAGE_TIMESTAMP_HEADER_NAME + " is missing but is a required message header."); } if (message.getMessageType() == null) { throw new MessageFormatException( Message.MESSAGE_TYPE_HEADER_NAME + " is missing but is a required message header."); } if (message.getOriginSystemId() == null) { throw new MessageFormatException( Message.ORIGIN_SYSTEM_ID_HEADER_NAME + " is missing but is a required message header."); } if (message.getContentType() == null) { throw new MessageFormatException( Message.CONTENT_TYPE_HEADER_NAME + " is missing but is a required message header."); } if (Strings.isNullOrEmpty(message.getMessageBody())) { throw new MessageFormatException("Message body is missing but is a required."); } }
public String sendRR(Message message, EndPoint[] to, IAsyncCallback cb) { String messageId = message.getMessageId(); callbackMap_.put(messageId, cb); for (int i = 0; i < to.length; ++i) { sendOneWay(message, to[i]); } return messageId; }
void deliverIncomingMessage(final Message message) { long mid = message.getMessageId(); long rmid = message.getRequestMessageId(); Object payload = null; Exception exception = null; if (message.getFlag() == Message.ERROR) { exception = (Exception) message.getPayload(); exception.printStackTrace(); } else { payload = message.getPayload(); } ipci.deliverIncomingMessage(message.getIPCHandle(), mid, rmid, payload, exception); }
/** * The format looks as follows: * * <p>32bit p2p version - 32bit id - 4bit message type - 4bit message name - 160bit sender id - * 16bit tcp port - 16bit udp port - 160bit recipient id - 16bit (4x4)content type - 8bit network * address information. It total, the header is of size 56 bytes. * * @param buffer The Netty buffer to fill * @param message The message with the header that will be serialized * @return The buffer passed as an argument */ public static ChannelBuffer encodeHeader(final ChannelBuffer buffer, final Message message) { buffer.writeInt(message.getVersion()); // 4 buffer.writeInt(message.getMessageId()); // 8 buffer.writeByte((message.getType().ordinal() << 4) | message.getCommand().ordinal()); // 9 buffer.writeBytes(message.getSender().getID().toByteArray()); // 29 buffer.writeShort((short) message.getSender().portTCP()); // 31 buffer.writeShort((short) message.getSender().portUDP()); // 33 buffer.writeBytes(message.getRecipient().getID().toByteArray()); // 53 final int content = ((message.getContentType4().ordinal() << 12) | (message.getContentType3().ordinal() << 8) | (message.getContentType2().ordinal() << 4) | message.getContentType1().ordinal()); buffer.writeShort((short) content); // 55 // options int options = (message.getSender().getOptions() << 4) | message.getOptions(); buffer.writeByte(options); // 56 return buffer; }
private void onLanguageSelected(Message message) throws InvalidObjectException { String[] parts = message.getText().split("-->", 2); SendMessage sendMessageRequest = new SendMessage(); sendMessageRequest.setChatId(message.getChatId().toString()); if (LocalisationService.getInstance().getSupportedLanguages().containsKey(parts[0].trim())) { DatabaseManager.getInstance().putUserLanguage(message.getFrom().getId(), parts[0].trim()); sendMessageRequest.setText( LocalisationService.getInstance().getString("languageModified", parts[0].trim())); } else { sendMessageRequest.setText(LocalisationService.getInstance().getString("errorLanguage")); } sendMessageRequest.setReplayToMessageId(message.getMessageId()); ReplyKeyboardHide replyKeyboardHide = new ReplyKeyboardHide(); replyKeyboardHide.setHideKeyboard(true); replyKeyboardHide.setSelective(true); sendMessageRequest.setReplayMarkup(replyKeyboardHide); SenderHelper.SendApiMethod(sendMessageRequest, TOKEN); languageMessages.remove(message.getFrom().getId()); }
/** * Creates a message Id. If the message is a request, the peer address is the sender, otherwise * its the recipient. This is due to the fact that depending on the direction, peer address may * change, but its still considered the same message. * * @param message The message */ public MessageID(final Message message) { this( message.getMessageId(), message.isRequest() ? message.getSender() : message.getRecipient()); }
public IAsyncResult sendRR(Message message, EndPoint to) { IAsyncResult iar = new AsyncResult(); taskCompletionMap_.put(message.getMessageId(), iar); sendOneWay(message, to); return iar; }
public String sendRR(Message message, EndPoint to, IAsyncCallback cb) { String messageId = message.getMessageId(); callbackMap_.put(messageId, cb); sendOneWay(message, to); return messageId; }