Repository: caronc/apprise (language: python)

Issue:
Add Markdownv2 support for Telegram
:bulb: **The Idea**
Add MarkdownV2 support for more formatting options.
https://core.telegram.org/bots/api#markdownv2-style



Discussion / hints:
I don't think this is required; If you tell Apprise you're feeding it `markdown` and you're posting your information to Telegram as such, it will just pass it along as is.

Can you provide an example where this isn't working for you?
I believe apprise is using the [legacy markdown](https://core.telegram.org/bots/api#markdown-style), ie parse_mode=Markdown instead of parse_mode=MarkdownV2 which allows more options in terms of styling. For example underlining, strikethrough, spoiler, and combining styles (via nesting of "entities")
The markdown library is only used when markdown is provided, but the upstream service requires HTML.

That said, your point is valid. I'll investigate the markdown v2 library and see how well it integrates. 
Does apprise converts markdown to HTML internally, or rely on telegram to do it?
> Does apprise converts markdown to HTML internally, or rely on telegram to do it?

Default is HTML unless you add `?format=markdown` in the URL you feed. 

Fix patch:
diff --git a/apprise/plugins/NotifyTelegram.py b/apprise/plugins/NotifyTelegram.py
index dbea79b1a4..cce8af625a 100644
--- a/apprise/plugins/NotifyTelegram.py
+++ b/apprise/plugins/NotifyTelegram.py
@@ -82,6 +82,34 @@
 )
 
 
+class TelegramMarkdownVersion:
+    """
+    Telegram Markdown Version
+    """
+    # Classic (Original Telegram Markdown)
+    ONE = 'MARKDOWN'
+
+    # Supports strikethrough and many other items
+    TWO = 'MarkdownV2'
+
+
+TELEGRAM_MARKDOWN_VERSION_MAP = {
+    # v1
+    "v1": TelegramMarkdownVersion.ONE,
+    "1": TelegramMarkdownVersion.ONE,
+    # v2
+    "v2": TelegramMarkdownVersion.TWO,
+    "2": TelegramMarkdownVersion.TWO,
+    "default": TelegramMarkdownVersion.TWO,
+}
+
+TELEGRAM_MARKDOWN_VERSIONS = {
+    # Note: This also acts as a reverse lookup mapping
+    TelegramMarkdownVersion.ONE: 'v1',
+    TelegramMarkdownVersion.TWO: 'v2',
+}
+
+
 class TelegramContentPlacement:
     """
     The Telegram Content Placement
@@ -333,6 +361,12 @@ class NotifyTelegram(NotifyBase):
             'name': _('Topic Thread ID'),
             'type': 'int',
         },
+        'mdv': {
+            'name': _('Markdown Version'),
+            'type': 'choice:string',
+            'values': ('v1', 'v2'),
+            'default': 'v2',
+        },
         'to': {
             'alias_of': 'targets',
         },
@@ -346,7 +380,7 @@ class NotifyTelegram(NotifyBase):
 
     def __init__(self, bot_token, targets, detect_owner=True,
                  include_image=False, silent=None, preview=None, topic=None,
-                 content=None, **kwargs):
+                 content=None, mdv=None, **kwargs):
         """
         Initialize Telegram Object
         """
@@ -361,6 +395,17 @@ def __init__(self, bot_token, targets, detect_owner=True,
             self.logger.warning(err)
             raise TypeError(err)
 
+        # Get our Markdown Version
+        self.markdown_ver = \
+            TELEGRAM_MARKDOWN_VERSION_MAP[NotifyTelegram.
+                                          template_args['mdv']['default']] \
+            if mdv is None else \
+            next((
+                v for k, v in TELEGRAM_MARKDOWN_VERSION_MAP.items()
+                if str(mdv).lower().startswith(k)),
+                TELEGRAM_MARKDOWN_VERSION_MAP[NotifyTelegram.
+                                              template_args['mdv']['default']])
+
         # Define whether or not we should make audible alarms
         self.silent = self.template_args['silent']['default'] \
             if silent is None else bool(silent)
@@ -717,8 +762,7 @@ def send(self, body, title='', notify_type=NotifyType.INFO, attach=None,
 
         # Prepare Message Body
         if self.notify_format == NotifyFormat.MARKDOWN:
-            _payload['parse_mode'] = 'MARKDOWN'
-
+            _payload['parse_mode'] = self.markdown_ver
             _payload['text'] = body
 
         else:  # HTML
@@ -886,6 +930,7 @@ def url(self, privacy=False, *args, **kwargs):
             'silent': 'yes' if self.silent else 'no',
             'preview': 'yes' if self.preview else 'no',
             'content': self.content,
+            'mdv': TELEGRAM_MARKDOWN_VERSIONS[self.markdown_ver],
         }
 
         if self.topic:
@@ -990,6 +1035,10 @@ def parse_url(url):
         # Store our bot token
         results['bot_token'] = bot_token
 
+        # Support Markdown Version
+        if 'mdv' in results['qsd'] and len(results['qsd']['mdv']):
+            results['mdv'] = results['qsd']['mdv']
+
         # Support Thread Topic
         if 'topic' in results['qsd'] and len(results['qsd']['topic']):
             results['topic'] = results['qsd']['topic']


Test patch:
diff --git a/test/test_plugin_telegram.py b/test/test_plugin_telegram.py
index faa5347079..b640d8652d 100644
--- a/test/test_plugin_telegram.py
+++ b/test/test_plugin_telegram.py
@@ -122,6 +122,16 @@
     ('tgram://123456789:abcdefg_hijklmnop/lead2gold/?format=markdown', {
         'instance': NotifyTelegram,
     }),
+    ('tgram://123456789:abcdefg_hijklmnop/lead2gold/?format=markdown&mdv=v1', {
+        'instance': NotifyTelegram,
+    }),
+    ('tgram://123456789:abcdefg_hijklmnop/lead2gold/?format=markdown&mdv=v2', {
+        'instance': NotifyTelegram,
+    }),
+    ('tgram://123456789:abcdefg_hijklmnop/l2g/?format=markdown&mdv=bad', {
+        # Defaults to v2
+        'instance': NotifyTelegram,
+    }),
     ('tgram://123456789:abcdefg_hijklmnop/lead2gold/?format=html', {
         'instance': NotifyTelegram,
     }),