I am totally new to telegram_bot. I want to execute a bot.send_message()
in the following code (as commented in the code), but can’t do so. Please help.
!pip install python-telegram-bot --upgrade
import telegram
bot = telegram.Bot(token='**************')
bot.send_message(chat_id='******', text="I'm sorry Dave I'm afraid I can't do that.")
It errors out as :
1 bot.send_message('mardepbot',"I'm sorry Dave I'm afraid I can't do that.")
/usr/local/lib/python3.6/dist-packages/telegram/bot.py in decorator(self, *args, **kwargs)
63 def decorator(self, *args, **kwargs):
64 logger.debug('Entering: %s', func.__name__)
---> 65 result = func(self, *args, **kwargs)
66 logger.debug(result)
67 logger.debug('Exiting: %s', func.__name__)
/usr/local/lib/python3.6/dist-packages/telegram/bot.py in decorator(self, *args, **kwargs)
88 data['reply_markup'] = reply_markup
89
---> 90 result = self._request.post(url, data, timeout=kwargs.get('timeout'))
91
92 if result is True:
/usr/local/lib/python3.6/dist-packages/telegram/utils/request.py in post(self, url, data, timeout)
307 result = self._request_wrapper('POST', url,
308 body=json.dumps(data).encode('utf-8'),
--> 309 headers={'Content-Type': 'application/json'})
310
311 return self._parse(result)
/usr/local/lib/python3.6/dist-packages/telegram/utils/request.py in _request_wrapper(self, *args, **kwargs)
221 raise Unauthorized(message)
222 elif resp.status == 400:
--> 223 raise BadRequest(message)
224 elif resp.status == 404:
225 raise InvalidToken()
BadRequest: Chat not found
2
Answers
I just solved the similar issue. Please check:
You can’t send a message to a string (‘mardepbot’) as address. If mardepbot is the bot, you are using, then you made 2 errors; then you should use your own ID to send a message to yourself.