Repository: PokemonGoF/PokemonGo-Bot

Issue:
telegram_handler : TypeError: expected string or buffer
<!--

===============ISSUE SECTION===============

Before you create an Issue, please check the following:

1. Have you validated that your config.json is valid JSON? Use http://jsonlint.com/ to check.
2. Have you [searched our issue tracker](https://github.com/PokemonGoF/PokemonGo-Bot/issues?q=is%3Aissue+sort%3Aupdated-desc) to see if the issue already exists? If so, comment on that issue instead rather than creating a new issue.
3. Are you running on the `master` branch? We work on the `dev` branch and then add that functionality to `master` when it is stable. Your issue may be fixed on `dev` and there is no need for this issue, just wait and it will eventually be merged to `master`.
4. All Issue sections MUST be completed to help us determine the actual problem and find its cause
-->
### Expected Behavior

<!-- Tell us what you expect to happen -->

Bot to run and telegram to respond to /info request.
### Actual Behavior

<!-- Tell us what is happening -->

The telegram handler crashes
### Your FULL config.json (remove your username, password, gmapkey and any other private info)

<!-- Provide your FULL config file, feel free to use services such as pastebin.com to reduce clutter -->

  "type": "TelegramTask",
        "config": {
          "enabled": true,
          "master": null,
          "// old syntax, still supported: alert_catch": ["all"],
          "// new syntax:": {},
          "alert_catch": {
            "all": {"operator": "and", "cp": 1300, "iv": 0.95},
            "Snorlax": {"operator": "or", "cp": 900, "iv": 0.9}
### Output when issue occurred

<!-- Provide a reasonable sample from your output log (not just the error message), feel free to use services such as pastebin.com to reduce clutter -->

> Traceback (most recent call last):
>   File "/home/felis/PokemonGo-Bot/local/lib/python2.7/site-packages/eventlet/hubs/poll.py", line 115, in wait
>     listener.cb(fileno)
>   File "/home/felis/PokemonGo-Bot/local/lib/python2.7/site-packages/eventlet/green/thread.py", line 41, in __thread_body
>     func(_args, *_kwargs)
>   File "/home/felis/PokemonGo-Bot/pokemongo_bot/event_handlers/telegram_handler.py", line 82, in run
>     if not re.match(r'^[0-9]+$', self.master):
>   File "/home/felis/PokemonGo-Bot/lib/python2.7/re.py", line 141, in match
>     return _compile(pattern, flags).match(string)
> TypeError: expected string or buffer
> Removing descriptor: 16
### Steps to Reproduce

<!-- Tell us the steps you have taken to reproduce the issue -->

Unsure how it started. Now the error happens every startup since the bot is receiving a previous /info request.
master: null is on purpose. Multiple people are watching the same bot instance, so we don't need push notification.
### Other Information

OS: Ubuntu 16.04.1

<!-- Tell us what Operating system you're using --> 

Branch: dev

<!-- dev or master --> 

Git Commit: c270999a79d8e17f43e846249738b7b1f91936b8

<!-- run 'git log -n 1 --pretty=format:"%H"' --> 

Python Version: Python 2.7.12

<!-- run 'python -V' and paste it here) --> 

Any other relevant files/configs (eg: path files) 

<!-- Anything else which may be of relevance -->

<!-- ===============END OF ISSUE SECTION=============== -->

<!-- Note: Delete these lines and everything BELOW if creating an Issue -->

telegram_handler : TypeError: expected string or buffer
<!--

===============ISSUE SECTION===============

Before you create an Issue, please check the following:

1. Have you validated that your config.json is valid JSON? Use http://jsonlint.com/ to check.
2. Have you [searched our issue tracker](https://github.com/PokemonGoF/PokemonGo-Bot/issues?q=is%3Aissue+sort%3Aupdated-desc) to see if the issue already exists? If so, comment on that issue instead rather than creating a new issue.
3. Are you running on the `master` branch? We work on the `dev` branch and then add that functionality to `master` when it is stable. Your issue may be fixed on `dev` and there is no need for this issue, just wait and it will eventually be merged to `master`.
4. All Issue sections MUST be completed to help us determine the actual problem and find its cause
-->
### Expected Behavior

<!-- Tell us what you expect to happen -->

Bot to run and telegram to respond to /info request.
### Actual Behavior

<!-- Tell us what is happening -->

The telegram handler crashes
### Your FULL config.json (remove your username, password, gmapkey and any other private info)

<!-- Provide your FULL config file, feel free to use services such as pastebin.com to reduce clutter -->

  "type": "TelegramTask",
        "config": {
          "enabled": true,
          "master": null,
          "// old syntax, still supported: alert_catch": ["all"],
          "// new syntax:": {},
          "alert_catch": {
            "all": {"operator": "and", "cp": 1300, "iv": 0.95},
            "Snorlax": {"operator": "or", "cp": 900, "iv": 0.9}
### Output when issue occurred

<!-- Provide a reasonable sample from your output log (not just the error message), feel free to use services such as pastebin.com to reduce clutter -->

> Traceback (most recent call last):
>   File "/home/felis/PokemonGo-Bot/local/lib/python2.7/site-packages/eventlet/hubs/poll.py", line 115, in wait
>     listener.cb(fileno)
>   File "/home/felis/PokemonGo-Bot/local/lib/python2.7/site-packages/eventlet/green/thread.py", line 41, in __thread_body
>     func(_args, *_kwargs)
>   File "/home/felis/PokemonGo-Bot/pokemongo_bot/event_handlers/telegram_handler.py", line 82, in run
>     if not re.match(r'^[0-9]+$', self.master):
>   File "/home/felis/PokemonGo-Bot/lib/python2.7/re.py", line 141, in match
>     return _compile(pattern, flags).match(string)
> TypeError: expected string or buffer
> Removing descriptor: 16
### Steps to Reproduce

<!-- Tell us the steps you have taken to reproduce the issue -->

Unsure how it started. Now the error happens every startup since the bot is receiving a previous /info request.
master: null is on purpose. Multiple people are watching the same bot instance, so we don't need push notification.
### Other Information

OS: Ubuntu 16.04.1

<!-- Tell us what Operating system you're using --> 

Branch: dev

<!-- dev or master --> 

Git Commit: c270999a79d8e17f43e846249738b7b1f91936b8

<!-- run 'git log -n 1 --pretty=format:"%H"' --> 

Python Version: Python 2.7.12

<!-- run 'python -V' and paste it here) --> 

Any other relevant files/configs (eg: path files) 

<!-- Anything else which may be of relevance -->

<!-- ===============END OF ISSUE SECTION=============== -->

<!-- Note: Delete these lines and everything BELOW if creating an Issue -->



Discussion:

Resolving patch:
diff --git a/pokemongo_bot/event_handlers/telegram_handler.py b/pokemongo_bot/event_handlers/telegram_handler.py
--- a/pokemongo_bot/event_handlers/telegram_handler.py
+++ b/pokemongo_bot/event_handlers/telegram_handler.py
@@ -79,7 +79,7 @@ def run(self):
                         self.bot.logger.info("message from {} ({}): {}".format(update.message.from_user.username, update.message.from_user.id, update.message.text))
                         if self.master and self.master not in [update.message.from_user.id, "@{}".format(update.message.from_user.username)]:
                             continue
-                        if not re.match(r'^[0-9]+$', self.master):
+                        if self.master and not re.match(r'^[0-9]+$', str(self.master)):
                             # the "master" is not numeric, set self.master to update.message.chat_id and re-instantiate the handler
                             newconfig = self.config
                             newconfig['master'] = update.message.chat_id


Test patch: