You need to write a Python program to send messages to Skype chat. Skype4Py doesn’t work for 64-bit Python.

Are there any alternatives for working with Skype other than Skype4Py, and is there a Skype API for sending messages?

1 answer 1

Skype bot can send a message using the REST API :

POST /v2/conversations/8:alice/activities HTTP/1.1 Host: apis.skype.com Authorization: Bearer <redacted oauth2 token> { "message": {"content" : "Hi! (wave)"} } 

for example, to send a message skypeid user on Python:

 #!/usr/bin/env python2 import json from urllib2 import urlopen, Request def send_message(message, skypeid, token, host='apis.skype.com'): url = 'https://{host}/v2/conversations/8:{skypeid}/activities'.format(**vars()) headers = dict(Authorization='Bearer ' + token) data = json.dumps(dict(message=dict(content=message))).encode() urlopen(Request(url, data, headers)).close() 

where token can be obtained using another http POST request:

 from urllib import urlencode def get_access_token(client_id, client_secret): # from messaging/auth-service.js in skype-sdk # NOTE: unlike the documented way in /skype/bots/docs/; # this approach works for me url = 'https://login.microsoftonline.com/common/oauth2/v2.0/token' data = urlencode(dict(client_id=client_id, scope='https://graph.microsoft.com/.default', grant_type='client_credentials', client_secret=client_secret)).encode() return json.loads(urlopen(url, data).read().decode())['access_token'] 

access_token can be cached expires_in seconds.

To get client_id , client_secret you need to register the application with your microsoft account and create a password .

Then the Skype bot itself must also be registered to get a link by which you can add the bot to Skype contacts (before publishing the bot, you can find it by this link).

To receive response messages you need to specify when creating a Skype bot https webhook. For the test, you can ngrok http 8000 , which prints the url, which you can specify as a public webhook. At the same time, the http (not https) server is locally sufficient to start, which json can receive on the specified port 8000, for example:

 #!/usr/bin/env python3 from aiohttp import web # $ pip install aiohttp async def handle(request): messages = await request.json() for message in messages: print(message) return web.HTTPCreated() # 201 app = web.Application() app.router.add_route('POST', '/v1/chat', handle) web.run_app(app, host='localhost', port=8000, ssl_context=None) 

In the subject article on Habrahabr: How to create your own bot for Skype. What is not written in the documentation .

  • and you can write more in detail how to create your own server? - Vindict
  • Already the second day I have been struggling with this issue, but the material found is so extensive, and there is so little experience in this that I get lost somewhere in the process of creating a server by tutorial. developer.microsoft.com/en-us/skype/bots/docs/tutorials/… I’m trying to create a server using this instruction, but I’ve got confused on the topic Create server.js - Vindict
  • @Vindict: any http-server to which json in the POST request can be sent is suitable. For a sample, you can even start commands with ncat -k -l 8000 (requests to the terminal are printed). Here is an example of a bot that Morse code translates there / here - jfs
  • On 01/17/2019 OAuth returns a token with the words 'The provided' OAuth 'ticket failed authentication.' What changed? - Pavel Pesheev