Function to initialize a telegram bot that you can talk to and control your InstaPy Bot :return:
(self)
| 100 | self.__logger.setLevel(logging.DEBUG) |
| 101 | |
| 102 | def telegram_bot(self): |
| 103 | """ |
| 104 | Function to initialize a telegram bot that you can talk to and control your InstaPy Bot |
| 105 | :return: |
| 106 | """ |
| 107 | if self.token == "": |
| 108 | self.__logger.warning( |
| 109 | "You need to set token for InstaPyTelegramBot to work" |
| 110 | ) |
| 111 | return |
| 112 | if self.telegram_username == "": |
| 113 | self.__logger.warning( |
| 114 | "You need to set telegram_username for InstaPyTelegramBot to work" |
| 115 | ) |
| 116 | return |
| 117 | if self.instapy_session is None: |
| 118 | self.__logger.warning( |
| 119 | "You need to set instapy_session for InstaPyTelegramBot to work" |
| 120 | ) |
| 121 | return |
| 122 | |
| 123 | self._clean_web_hooks() |
| 124 | |
| 125 | if self.proxy is not None: |
| 126 | updater = Updater( |
| 127 | token=self.token, |
| 128 | use_context=True, |
| 129 | user_sig_handler=self.end, |
| 130 | request_kwargs=self.proxy, |
| 131 | ) |
| 132 | else: |
| 133 | updater = Updater( |
| 134 | token=self.token, use_context=True, user_sig_handler=self.end |
| 135 | ) |
| 136 | self.__updater = updater |
| 137 | |
| 138 | dispatcher = updater.dispatcher |
| 139 | self.__context = dispatcher |
| 140 | dispatcher.add_error_handler(self._error_callback) |
| 141 | start_handler = CommandHandler("start", self._start) |
| 142 | dispatcher.add_handler(start_handler) |
| 143 | report_handler = CommandHandler("report", self._report) |
| 144 | dispatcher.add_handler(report_handler) |
| 145 | report_handler = CommandHandler("stop", self._stop) |
| 146 | dispatcher.add_handler(report_handler) |
| 147 | unknown_handler = MessageHandler(Filters.command, self._unknown) |
| 148 | dispatcher.add_handler(unknown_handler) |
| 149 | updater.start_polling() |
| 150 | if self.__chat_id is not None: |
| 151 | # session was restored, send a message saying that instapy session is starting |
| 152 | self.__context.bot.send_message( |
| 153 | self.__chat_id, text="Telegram session restored, InstaPy starting\n" |
| 154 | ) |
| 155 | |
| 156 | def send_message(self, text=""): |
| 157 | """ |
no test coverage detected