N
https://gist.github.com/zed/5b7542e7acb2c716c606385966f3a51a May send a message using https://developer.microsoft.com/en-us/skype/bots/docs/api/chat#Activities :POST /v2/conversations/8:alice/activities HTTP/1.1
Host: apis.skype.com
Authorization: Bearer <redacted oauth2 token>
{
"message": {"content" : "Hi! (wave)"}
}
for example, message line skypeid User on Pitton: #!/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 by 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 Cash. expires_in One second.To get it. client_id♪ client_secret necessary https://apps.dev.microsoft.com/?mkt=en-us#/appList ♪Then he himself https://developer.microsoft.com/en-us/skype/bots/manage in order to obtain a reference for can be added to the Skype-Contact (before the Bota is published, this reference can be found).In order to obtain feedback, reference should be made to the creation of Skype Botá https webhook. For testing, we can. https://developer.microsoft.com/en-us/skype/bots/docs/tutorials/simple-nodejs Use a url that can be indicated as a public webhook. At this point, it is sufficiently localized to operate a server that json can accept on the 8,000 port, 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)
On the subject of Habrahab: https://habrahabr.ru/post/281296/ ♪