Object
MessageContext

public class MessageContext extends Object
MessageContext is a wrapper class to the Update, originating end-user and the arguments present in its message (if any).

A user is not bound to the usage of this higher level context as it's possible to fetch the underlying Update using update().

Author:
Abbas Abou Daya
  • Method Details

    • newContext

      public static MessageContext newContext(Update update, User user, Long chatId, BaseAbilityBot bot, String... arguments)
    • user

      public User user()
      Returns:
      the originating Telegram user of this update
    • chatId

      public Long chatId()
      Returns:
      the originating chatId, maps correctly to both group and user-private chats
    • bot

      public BaseAbilityBot bot()
      Returns:
      the bot in which this message is executed
    • arguments

      public String[] arguments()
      If there's no message in the update, then this will an empty array.
      Returns:
      the text sent by the user message.
    • firstArg

      public String firstArg()
      Returns:
      the first argument directly after the command
      Throws:
      IllegalStateException - if message has no arguments
    • secondArg

      public String secondArg()
      Returns:
      the second argument directly after the command
      Throws:
      IllegalStateException - if message has no arguments
    • thirdArg

      public String thirdArg()
      Returns:
      the third argument directly after the command
      Throws:
      IllegalStateException - if message has no arguments
    • update

      public Update update()
      Returns:
      the actual update behind this context
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object