Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Skype listener code
"""
A listener for Skype.
"""
import json
import boto3
from skpy import SkypeEventLoop, SkypeNewMessageEvent
import skype_credentials as skype_creds
import aws_credentials as aws_creds
class SkypeListener(SkypeEventLoop):
"Listen to a channel continuously"
def __init__(self):
username = skype_creds.USERNAME
password = skype_creds.PASSWORD
token_file = '.tokens-app'
super(SkypeListener, self).__init__(username, password, token_file)
self.sns = boto3.client('sns',
aws_access_key_id=aws_creds.ACCESS_KEY,
aws_secret_access_key=aws_creds.SECRET_KEY,
region_name=aws_creds.AWS_REGION)
def onEvent(self, event):
if isinstance(event, SkypeNewMessageEvent):
default = "Skype listener: Investigate if you see this."
message = {"user_id":event.msg.userId,
"chat_id":event.msg.chatId,
"msg":event.msg.content}
send_message = json.dumps({"default":json.dumps(message)})
response = self.sns.publish(TopicArn = aws_creds.SNS_TOPIC,
Message = send_message,
MessageStructure='json')
#----START OF SCRIPT
if __name__ == "__main__":
big_bro = SkypeListener()
big_bro.loop()
import os
ACCESS_KEY=os.environ.get('AWS_ACCESS_KEY_ID')
SECRET_KEY=os.environ.get('AWS_SECRET_ACCESS_KEY')
AWS_REGION=os.environ.get('AWS_DEFAULT_REGION')
SNS_TOPIC="SNS topic to publish"
[Unit]
Description=The Skype listener service
[Service]
user=your_user
WorkingDirectory=path_of_py_file
VIRTUAL_ENV=path_to_bin_of_virtual_env
Environment=PATH=$VIRTUAL_ENV:$PATH
ExecStart=path_to_bin_of_virtual_env/python qxf2_skype_listener.py
Restart=on-failure
[Install]
WantedBy=multi-user.target
USERNAME = 'skype_account'
PASSWORD = 'skype_password'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment