Beispiel #1
0
 def send_text_msg(self):
     self.clear_screen()
     self.print_line("#")
     self.print_bold("Text Edit Mode")
     self.print_dotline()
     self.print_wrapmsg(
         "Instruction: Enter/Paste your content at bellow. Ctrl-D to send it."
     )
     self.print_dotline()
     contents = []
     while True:
         try:
             line = raw_input("")
         except EOFError:
             break
         contents.append(line)
     text = "\n".join(contents)
     self.print_dotline()
     self.print_line("=")
     print("server status...")
     txtmsg = TextMessage()
     txtmsg.set_text_body(text)
     self.server.send_message(txtmsg)
     self.print_line("#")
     self.pasue_screen()
def deliver_text_message_to_receiver(message: TextMessage):
    # If the message is too large, don't deliver the message directly.
    # For now, drop the message, in future it can be sent as a link to a storage bucket.
    if (message.get_text_message_size() > 100):
        raise Exception('Message too large to send {} > 100 bytes',
                        message.get_message_size())

    print('Message "{}" delivered successfully to {}'.format(
        message.get_text_message_content(), message.get_receiver()))
    pass
def send_text_message(message: TextMessage):
    # 1. Discard empty strings.
    if (message.get_text_message_content() == ''):
        raise Exception('Cannot send empty string')

    # 2. Ensure content is not offensive.
    check_for_offensive_content(message.get_text_message_content())

    # 3. Store the message safely.
    store_message(message)

    # 4. Deliver the message to the receiver.
    deliver_text_message_to_receiver(message)
Beispiel #4
0
def deliver_text_message_to_receiver(message: TextMessage):
    # Logic to actually send the message to the user. It may happen through some queueing mechanism.
    # Out of syllabus for this exercise :')

    # If the message is too large, don't deliver the message directly.
    # For now, drop the message, in future it can be sent as a link to a storage bucket.
    if (message.get_text_message_size() > 100):
        raise Exception('Message too large to send {} > 100 bytes',
                        message.get_message_size())

    print('Message "{}" delivered successfully to {}'.format(
        message.get_text_message_content(), message.get_receiver()))
    pass
Beispiel #5
0
def handle_post(request):
    print request.body
    message = TextMessage.from_xml(request.body)
    bot = Robot()
    bot.add_handler(cacti.handler)
    reply = bot.get_reply(message)
    return HttpResponse(reply, content_type="application/xml")
Beispiel #6
0
    def _message(self, msg):
        """
        Process incoming message stanzas. Be aware that this also
        includes MUC messages and error messages. It is usually
        a good idea to check the messages's type before processing
        or sending replies.

        Arguments:
            msg -- The received message stanza. See the documentation
                   for stanza objects and the Message stanza to see
                   how it may be used.
        """
        logging.debug("Begin handling message event")
        logging.debug("Incoming message: %s", msg)
        # TODO: Have the bot deal with presences/other message stanzas
        # FOR NOW only send the bot chat messages
        if msg['type'] in ('chat', 'normal'):
            jid_from = msg['from']
            # TODO: hook up the brain
            # user = self.robot.brain.userForId(msg['from'])
            user = User(jid_from)
            message = TextMessage(user, msg['body'], id=msg['id'])
            self.robot.receive(message)

        logging.debug("End handling message event.")
Beispiel #7
0
 def __init__(self,
              uri: str,
              label: str,
              message: Message = None,
              messages: List[Message] = None):
     self.uri = uri
     self.label = label
     self.messages = messages or ([TextMessage(message)] if message else [])
Beispiel #8
0
    def _process_msg(self):
        """
        Process a msg event.

        NOTE: this could be either a private message
        or a public message.
        """
        user = self._client.users.search(self._event_data.get('handle'))
        msg = TextMessage(self._event_data)
        user.messages.append(msg)

        self._client.run_method(self._method, *(user, msg))
Beispiel #9
0
    def get_reply(self, num):
        if not self.is_support(num):
            reply = TextMessage(self.navigate, **self.from_to)
            return reply.render_xml()

        reply = ArticlesMessage(**self.from_to)
        feature = self.features[num]
        reply.add_article(Article(**feature))
        return reply.render_xml()
Beispiel #10
0
from PIL import Image
from android_client_handler import send_message
from message import Message, TextMessage, ImageMessage

if __name__ == "__main__":
    # Call the android/iOS handler code to send a message.
    # In real world, these functions will be called from your Flask or Django server methods.
    # Don't worry about them for now - let's live in a simple world :)

    # Amar sends a text message.
    message_1 = TextMessage()
    message_1.set_sender('SENDER_Amar')
    message_1.set_receiver('RECEIVER_Abhinaya')
    message_1.set_message_content(
        'Hello, Have you checked out https://blog.crio.do?')

    send_message(message_1)

    # Amulya sends an image message.
    message_2 = ImageMessage()
    message_2.set_sender('SENDER_Amulya')
    message_2.set_receiver('RECEIVER_Cratos')

    # Some logic to send the image as bytes. You can ignore it safely.
    img_path = 'oop_way_with_polymorphism/CrioLogo.png'
    img = Image.open(img_path)
    with open(img_path, "rb") as image:
        f = image.read()
        image_byte = bytes(f)
    message_2.set_message_content(image_byte,
                                  image_resolution=img.size,
Beispiel #11
0
 def repeat_handler(message):
     content = message.content
     msg = dict(from_user=message.to_user, to_user=message.from_user)
     reply = TextMessage(content, **msg)
     return reply.render_xml()
Beispiel #12
0
 def onopen(self):
     print 'Connection established, sending "foo"'
     self.send(TextMessage('foo'))
Beispiel #13
0
 def handle(self):
     print 'Got connection from {}'.format(self.client_address)
     txtmsg = TextMessage()
     txtmsg.set_text_body("hello guest!")
     self.request.sendall(txtmsg.as_string())
Beispiel #14
0
from PIL import Image
from android_client_handler import send_text_message, send_image_message
from message import Message, TextMessage, ImageMessage

if __name__== "__main__":

    # Devyansh sends a text message.
    message_1 = TextMessage()
    message_1.set_sender('SENDER_Devyansh')
    message_1.set_receiver('RECEIVER_Rohan')
    message_1.set_text_message_content('Hello, How are you doing?')

    send_text_message(message_1)

    # Rodric sends an image message.
    message_2 = ImageMessage()
    message_2.set_sender('SENDER_Rodric')
    message_2.set_receiver('RECEIVER_Steve')

    img_path = 'CrioLogo.png'
    img = Image.open(img_path)
    with open(img_path, "rb") as image:
        f = image.read()
        image_byte = bytes(f)
    message_2.set_image_message_content(image_byte,
                                        image_resolution=img.size, image_metadata=img.mode)
    send_image_message(message_2)

Beispiel #15
0
from PIL import Image
from android_client_handler import send_message
from message import Message, TextMessage, ImageMessage

if __name__== "__main__":

    # Amar sends a text message.
    message_1 = TextMessage()
    message_1.set_sender('SENDER_Amar')
    message_1.set_receiver('RECEIVER_Abhinaya')
    message_1.set_message_content('Hello, How are you doing?')

    send_message(message_1)

    # Amulya sends an image message.
    message_2 = ImageMessage()
    message_2.set_sender('SENDER_Amulya')
    message_2.set_receiver('RECEIVER_Cratos')

    img_path = 'CrioLogo.png'
    img = Image.open(img_path)
    with open(img_path, "rb") as image:
        f = image.read()
        image_byte = bytes(f)
    message_2.set_message_content(image_byte,
                                  image_resolution=img.size, image_metadata=img.mode)
    send_message(message_2)

Beispiel #16
0
from telegram import MessageEntity, InputMediaPhoto


OPTIONS = [
    ChoiceOption(
        uri="/", 
        label="Erzähl mir etwas anderes, bitte!", 
        message="Was interessiert dich?",
        choices=["/sisi", "/drinkinghabits", "/skkg", "/silverfish"]
    ),
    LeafOption(
        uri="/silverfish",
        label="Erzähl mir mehr von dir.",
        messages=[
            TextMessage(
                "Nett, dass du fragst\\. Ich bin ein [Silberfischchen](https://de.wikipedia.org/wiki/Silberfischchen), wohne hier im Depot und kümmere mich um den Erhalt der Sammlung\\.",
                markdown = True,
            ),
        ],
        next_option="/restart",
    ),
    ChoiceOption(
        uri="/restart",
        label="Soll ich dir etwas anderes erzählen?",
        messages=[
            RandomMessage([
                TextMessage("Soll ich dir etwas anderes erzählen?"),
                TextMessage("Interessiert dich eines dieser Themen?")
            ])
        ],
        # TODO create new choice option that randomly picks a sublist if there are too man (and offers an option to show other options as well)
        choices=["/sisi", "/drinkinghabits", "/skkg", "/silverfish"],
Beispiel #17
0
    if len(sys.argv) < 3:
        print >> sys.stderr, 'Usage: python %s HOST PORT' % sys.argv[0]
        sys.exit(1)

    host = sys.argv[1]
    port = int(sys.argv[2])

    sock = websocket()
    sock.connect((host, port))
    sock.settimeout(1.0)
    conn = Connection(sock)

    try:
        try:
            while True:
                msg = TextMessage(raw_input())
                print 'send:', msg
                conn.send(msg)

                try:
                    print 'recv:', conn.recv()
                except socket.timeout:
                    print 'no response'
        except EOFError:
            conn.close()
    except SocketClosed as e:
        if e.initialized:
            print 'closed connection'
        else:
            print 'other side closed connection'