<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def to(self, target: typing.Union[types.Message, types.Chat, types.base.Integer, types.base.String]):
 """ Send to chat :param target: message or chat or id :return: """

        if isinstance(target, types.Message):
            chat_id = target.chat.id
        elif isinstance(target, types.Chat):
            chat_id = target.id
        elif isinstance(target, (int, str)):
            chat_id = target
        else:
            raise TypeError(f"Bad type of target. ({type(target)})")

        setattr(self, 'chat_id', chat_id)
        return self