Help - Search - Members - Calendar
Full Version: Skype4Py handle incoming chat messages
Skype Community > English > Development, Betas and Skype Garage > Skype Public API
BLT
Hi,
i am writing a simple skype application using the skype4py API, but i can't handle incoming chat messages. Which event handling from the Skype4Py API is responsible to inform me of new chat messages, or to handle changes in the messages.

Thank you in advance.

Regards,
Boian
Avo Nappo
> Which event handling from the Skype4Py API is responsible to inform
> me of new chat messages

Its OnMessageStatus.

CODE
#--------------------------------------------------------------------------------------------------
#  Python / Skype4Py example that prints out chat messages
#
#  Tested with  Skype4Py version 0.9.28.5 and Skype verson 3.8.0.96

import sys
import Skype4Py

#----------------------------------------------------------------------------------------------------
# Fired on attachment status change. Here used to re-attach this script to
# Skype in case attachment is lost. Just in case.

def OnAttach(status):
    print 'API attachment status: ' + skype.Convert.AttachmentStatusToText(status)
    if status == Skype4Py.apiAttachAvailable:
        skype.Attach();

    if status == Skype4Py.apiAttachSuccess:
       print('******************************************************************************');
      
        
#----------------------------------------------------------------------------------------------------
# Fired on chat message status change.
# Statuses can be: 'UNKNOWN' 'SENDING' 'SENT' 'RECEIVED' 'READ'        

def OnMessageStatus(Message, Status):
    if Status == 'RECEIVED':
        print(Message.FromDisplayName + ': ' + Message.Body);
    if Status == 'SENT':
        print('Myself: ' + Message.Body);

              
#----------------------------------------------------------------------------------------------------
# Creating instance of Skype object, assigning handler functions and
# attaching to Skype.

skype = Skype4Py.Skype();
skype.OnAttachmentStatus = OnAttach;
skype.OnMessageStatus = OnMessageStatus;

print('******************************************************************************');
print 'Connecting to Skype..'
skype.Attach();

#----------------------------------------------------------------------------------------------------
# Looping until user types 'exit'

Cmd = '';
while not Cmd == 'exit':
    Cmd = raw_input('');
BLT
Thanks for the reply!

I will test it today evening, and post the result.

Only for information i will test it with the latest Skype4Py (1.x) and Skype 2.0.x (latest stable Skype version on Linux).

Regards
Boian
awahlig
@BLT,

yes, you're interested in

MessageStatus(Message, Status)

event. If the Status == Skype4Py.cmsReceived then Message is an object with the new incoming chat message. See the Skype4Py.chat.IChatMessage for more info about this object. For example you can get the message body from the Body attribute.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.