Class 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 Detail

      • newContext

        public static MessageContext newContext​(org.telegram.telegrambots.meta.api.objects.Update update,
                                                org.telegram.telegrambots.meta.api.objects.User user,
                                                Long chatId,
                                                String... arguments)
      • user

        public org.telegram.telegrambots.meta.api.objects.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
      • 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 org.telegram.telegrambots.meta.api.objects.Update update()
        Returns:
        the actual update behind this context
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object