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 _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.")
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 [])
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))
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,
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())
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"],
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'
def onopen(self): print 'Connection established, sending "foo"' self.send(TextMessage('foo'))