-
-
Save qxf2/eef46b8744dc9a8be49036ec65c45839 to your computer and use it in GitHub Desktop.
How Qxf2 Skype sender endpoint has been setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Qxf2's Skype sender | |
""" | |
from flask import Flask, jsonify, request | |
from skpy import Skype, SkypeAuthException, SkypeConnection | |
import skype_credentials as creds | |
app = Flask(__name__) | |
def login(username, password, token_file='.tokens-app'): | |
"Login to Skype" | |
sk = Skype(connect=False) | |
sk.conn.setTokenFile(token_file) | |
try: | |
sk.conn.readToken() | |
except SkypeAuthException: | |
sk.conn.setUserPwd(username, password) | |
sk.conn.getSkypeToken() | |
return sk | |
def post_message(sk, channel_id, msg): | |
"Post a message to a given channel" | |
result_flag = False | |
try: | |
sk.conn.verifyToken(SkypeConnection.Auth.SkypeToken) | |
channel = sk.chats.chat(channel_id) | |
channel.sendMsg(msg, rich=True) | |
result_flag = True | |
except Exception as e: | |
print(e) | |
return result_flag | |
@app.route('/send-message', methods=['POST']) | |
def send_message_endpoint(): | |
"Send the required message" | |
request_data = request.get_json() | |
api_key = request_data.get('API_KEY', '') | |
channel_id = request_data.get('channel', None) | |
msg = request_data.get('msg', None) | |
if api_key != creds.API_KEY: | |
return jsonify({'msg':'incorrect API key'}), 401 | |
if not msg or not channel_id: | |
return jsonify({'msg':'missing request parameters'}), 400 | |
sk = login(creds.USERNAME, creds.PASSWORD) | |
post_message(sk, channel_id, msg) | |
return jsonify({'msg':'Posted message'}), 200 | |
@app.route("/") | |
def index(): | |
"Index page" | |
return jsonify({'msg':'this works'}), 200 | |
#----START OF SCRIPT | |
if __name__=='__main__': | |
app.run('0.0.0.0', debug=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USERNAME = 'SKYPE ID' | |
PASSWORD = 'YOUR PASSWORD' | |
API_KEY = 'SOMETHING_YOU_SET' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment