Repository: line/line-bot-sdk-python
Pull request #262 (2020-04-15 16:27:58)

feat: support LINE emoji in messages
fixed: #255 
- add Sticon model
- TextMessage tests
- add **sticon** in TextMessage 


Patch:
diff --git a/linebot/models/messages.py b/linebot/models/messages.py
index 5aca52f..244eb73 100644
--- a/linebot/models/messages.py
+++ b/linebot/models/messages.py
@@ -20,6 +20,7 @@ from abc import ABCMeta
 
 from future.utils import with_metaclass
 
+from linebot.models.sticon import Sticon
 from .base import Base
 
 
@@ -46,17 +47,28 @@ class TextMessage(Message):
     Message object which contains the text sent from the source.
     """
 
-    def __init__(self, id=None, text=None, **kwargs):
+    def __init__(self, id=None, text=None, sticon=None, **kwargs):
         """__init__ method.
 
         :param str id: Message ID
         :param str text: Message text
+        :param List sticon: Array of LINE emoji objects
         :param kwargs:
         """
         super(TextMessage, self).__init__(id=id, **kwargs)
 
         self.type = 'text'
         self.text = text
+        if sticon:
+            new_sticons = []
+            for action in sticon:
+                sticon_obj = self.get_or_new_from_json_dict(
+                    action, Sticon
+                )
+                if sticon_obj:
+                    new_sticons.append(sticon_obj)
+            self.sticon = new_sticons
+        self.sticon = sticon
 
 
 class ImageMessage(Message):
diff --git a/linebot/models/sticon.py b/linebot/models/sticon.py
new file mode 100644
index 0000000..6bd82d5
--- /dev/null
+++ b/linebot/models/sticon.py
@@ -0,0 +1,42 @@
+# -*- coding: utf-8 -*-
+
+#  Licensed under the Apache License, Version 2.0 (the "License"); you may
+#  not use this file except in compliance with the License. You may obtain
+#  a copy of the License at
+#
+#       https://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+#  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+#  License for the specific language governing permissions and limitations
+#  under the License.
+
+"""linebot.models.sticon module."""
+
+from __future__ import unicode_literals
+
+from abc import ABCMeta
+
+from future.utils import with_metaclass
+
+from .base import Base
+
+
+class Sticon(with_metaclass(ABCMeta, Base)):
+    """Sticon.
+
+    https://developers.line.biz/en/reference/messaging-api/#text-message
+
+    """
+
+    def __init__(self, index=None, product_id=None, sticon_id=None, **kwargs):
+        """__init__ method.
+
+        :param kwargs:
+        """
+        super(Sticon, self).__init__(**kwargs)
+
+        self.index = index
+        self.product_id = product_id
+        self.sticon_id = sticon_id


Test patch:
diff --git a/tests/models/test_text_message.py b/tests/models/test_text_message.py
new file mode 100644
index 0000000..73d8ef7
--- /dev/null
+++ b/tests/models/test_text_message.py
@@ -0,0 +1,59 @@
+# -*- coding: utf-8 -*-
+
+#  Licensed under the Apache License, Version 2.0 (the 'License'); you may
+#  not use this file except in compliance with the License. You may obtain
+#  a copy of the License at
+#
+#       https://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT
+#  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+#  License for the specific language governing permissions and limitations
+#  under the License.
+
+from __future__ import unicode_literals, absolute_import
+
+import unittest
+
+from linebot.models import TextMessage
+from linebot.models.sticon import Sticon
+from tests.models.serialize_test_case import SerializeTestCase
+
+
+class TestTextMessage(SerializeTestCase):
+    def test_sticon(self):
+        arg = {
+            "type": "text",
+            "text": "$ LINE emoji $",
+            'sticon': [
+                Sticon(
+                    index=0,
+                    product_id='5ac1bfd5040ab15980c9b435',
+                    sticon_id='001'
+                ),
+                Sticon(
+                    index=13,
+                    product_id='5ac1bfd5040ab15980c9b435',
+                    sticon_id='002'
+                ),
+            ]
+        }
+        self.assertEqual(
+            self.serialize_as_dict(arg, type=self.TEXT),
+            TextMessage(**arg).as_json_dict()
+        )
+
+    def test_null_sticon(self):
+        arg = {
+            "type": "text",
+            "text": "\uDBC0\uDC84 LINE original emoji"
+        }
+        self.assertEqual(
+            self.serialize_as_dict(arg, type=self.TEXT),
+            TextMessage(**arg).as_json_dict()
+        )
+
+
+if __name__ == '__main__':
+    unittest.main()