コード例 #1
0
ファイル: bot.py プロジェクト: dialogs/dialog-remind-bot
 def buttons(self, peer, title, options):
     return self.bot.messaging.send_message(peer, title, [
         InteractiveMediaGroup([
             InteractiveMedia(option[0], InteractiveMediaButton(*option))
             for option in options
         ])
     ]).wait()
コード例 #2
0
ファイル: bot.py プロジェクト: dialogs/dialog-trello-bot
 def select(self, peer, text, select_title, options, select_id="default"):
     return self.bot.messaging.send_message(peer, text, [
         InteractiveMediaGroup([
             InteractiveMedia(
                 select_id,
                 InteractiveMediaSelect(options, select_title, "choose"),
                 InteractiveMediaStyle.INTERACTIVEMEDIASTYLE_DANGER,
             )
         ])
     ])
コード例 #3
0
ファイル: votebot.py プロジェクト: dialogs/dialog-vote-bot
 def update_buttons(self, msg, title, options=None):
     if not options:
         return self.bot.messaging.update_message(
         msg, title) 
     else:    
         return self.bot.messaging.update_message(
             msg, title,
             [InteractiveMediaGroup(
                 [InteractiveMedia(
                     option[0],
                     InteractiveMediaButton(
                         *option)
                         )
                 for option in options]
             )]
         ) 
コード例 #4
0
class TestMessaging(unittest.TestCase):
    bot.internal.messaging = Messaging()
    bot.internal.updates = Updates()
    bot.internal.media_and_files = MediaAndFiles()

    test_file = "../dialog_bot_sdk/examples/files/example.png"

    peer = Peer(1, PEERTYPE_PRIVATE)
    message = Message(UUID(1, 1), UUID(0, 0), peer, None, [], [], 0, 0)
    outpeer = peers_pb2.OutPeer(type=PEERTYPE_PRIVATE, id=0, access_hash=0)
    mid = definitions_pb2.UUIDValue(msb=0, lsb=0)
    msg_content = messaging_pb2.MessageContent()
    msg_content.textMessage.text = "Hello"
    interactive_media = [
        InteractiveMediaGroup([
            InteractiveMedia("1", InteractiveMediaButton("Yes", "Да")),
            InteractiveMedia("2", InteractiveMediaButton("No", "Нет")),
        ])
    ]

    # msg_content_with_group = copy.deepcopy(msg_content)
    # group[0].render(msg_content_with_group.textMessage.media.add())
    # doc_msg = messaging_pb2.DocumentMessage(
    #     file_id=0,
    #     access_hash=0,
    #     file_size=60,
    #     name=""
    # )

    def test_send_message(self):
        send = bot.messaging.send_message(self.peer, "text",
                                          self.interactive_media)
        self.assertTrue(isinstance(send, AsyncTask))
        self.assertTrue(isinstance(send.wait(), UUID))

    def test_update_message(self):
        update = bot.messaging.update_message(self.message, "text",
                                              self.interactive_media)
        self.assertTrue(isinstance(update, AsyncTask))
        self.assertIsNone(update.wait())

    def test_delete_message(self):
        delete = bot.messaging.delete(self.message)
        self.assertTrue(isinstance(delete, AsyncTask))
        self.assertIsNone(delete.wait())

    def test_get_messages_by_id(self):
        msg = bot.messaging.get_messages_by_id([UUID(1, 1)])
        self.assertTrue(isinstance(msg, AsyncTask))
        self.assertTrue(isinstance(msg.wait()[0], Message))

    def test_messages_read(self):
        read = bot.messaging.messages_read(self.peer, 0)
        self.assertTrue(isinstance(read, AsyncTask))
        self.assertIsNone(read.wait())

    @patch('requests.put')
    def test_send_file(self, put):
        put.return_value = Put(200)
        send = bot.messaging.send_file(self.peer, self.test_file)
        self.assertTrue(isinstance(send, AsyncTask))
        self.assertTrue(isinstance(send.wait(), UUID))
        put.return_value = Put(400)
        send = bot.messaging.send_file(self.peer, self.test_file)
        self.assertTrue(isinstance(send, AsyncTask))
        self.assertIsNone(send.wait())

    @patch('requests.put')
    def test_send_media(self, put):
        put.return_value = Put(200)
        image = bot.internal.uploading.upload_file(self.test_file).wait()
        media = MessageMedia(image=ImageMedia(ImageLocation(image)))
        send = bot.messaging.send_media(self.peer, [media])
        self.assertTrue(isinstance(send, AsyncTask))
        self.assertTrue(isinstance(send.wait(), UUID))

    @patch('requests.put')
    def test_send_image(self, put):
        put.return_value = Put(200)
        send = bot.messaging.send_image(self.peer, self.test_file)
        self.assertTrue(isinstance(send, AsyncTask))
        self.assertTrue(isinstance(send.wait(), UUID))
        put.return_value = Put(400)
        send = bot.messaging.send_image(self.peer, self.test_file)
        self.assertTrue(isinstance(send, AsyncTask))
        self.assertIsNone(send.wait())

    def test_reply(self):
        reply = bot.messaging.reply(self.peer, [UUID(1, 1)], None,
                                    self.interactive_media)
        self.assertTrue(isinstance(reply, AsyncTask))
        self.assertTrue(isinstance(reply.wait(), UUID))

    def test_forward(self):
        forward = bot.messaging.forward(self.peer, [UUID(1, 1)], None,
                                        self.interactive_media)
        self.assertTrue(isinstance(forward, AsyncTask))
        self.assertTrue(isinstance(forward.wait(), UUID))

    def test_load_message_history(self):
        history = bot.messaging.load_message_history(
            self.peer, 0, ListLoadMode.LISTLOADMODE_BACKWARD, 1)
        self.assertTrue(isinstance(history, AsyncTask))
        self.assertTrue(isinstance(history.wait()[0], Message))
コード例 #5
0
from dialog_bot_sdk.bot import DialogBot
import grpc

from dialog_bot_sdk.entities.Peer import PeerType
from dialog_bot_sdk.entities.media.ImageMedia import ImageLocation
from dialog_bot_sdk.entities.media.WebpageMedia import WebPageMedia
from dialog_bot_sdk.entities.message.TextMessage import MessageMedia


SELECT = [
    InteractiveMediaGroup(
        [
            InteractiveMedia(
                "select_id",
                InteractiveMediaSelect({"Yes": "yes", "No": "no"}, "default", "choose"),
                InteractiveMediaStyle.INTERACTIVEMEDIASTYLE_DANGER,
            )
        ]
    )
]
BUTTONS = [
    InteractiveMediaGroup(
        [
            InteractiveMedia(
                "button_yes",
                InteractiveMediaButton("yes", "Yes"),
                InteractiveMediaStyle.INTERACTIVEMEDIASTYLE_PRIMARY,
            ),
            InteractiveMedia(
                "button_no",
コード例 #6
0
ファイル: bot.py プロジェクト: dialogs/dialog-remind-bot
 def select(self, title, values, select_id):
     return InteractiveMedia(
         select_id,
         InteractiveMediaSelect(values, title, "choose"),
         InteractiveMediaStyle.INTERACTIVEMEDIASTYLE_DANGER,
     )