ShyykoSerhiy / skyweb

Unofficial Skype API for nodejs via 'Skype (HTTP)' protocol.
MIT License
193 stars 44 forks source link

Skype Directory Search #64

Open cameron5906 opened 7 years ago

cameron5906 commented 7 years ago

Didn't see a feature for this, so I made it. This will search the Skype directory. Just give it a query

RequestService.prototype.search = function(skypeAccount, query, cb) {
    var reqID = 'skype.com-1.88.30-' + Math.random().toString(36).substring(0,8) + '-' + Math.random().toString(36).substring(0,4) + '-' + Math.random().toString(36).substring(0,4) + '-' + Math.random().toString(36).substring(0,4) + '-' + Math.random().toString(36).substring(0,12);
    var reqURI = 'https://skypegraph.skype.com/search/v1.1/namesearch/swx/?requestid=' + reqID + '&searchstring=' + query + '&locale=en-us';
    var _this = this;
    this.requestWithJar(reqURI, {
        method: 'OPTIONS',
        headers: {
            'accept':'*/*',
            'accept-encoding':'gzip, deflate, sdch, br',
            'accept-language':'en-US,en;q=0.8',
            'access-control-request-headers':'content-type,x-skypetoken',
            'access-control-request-method':'GET',
            'host': 'skypegraph.skype.com',
            'origin':'https://web.skype.com',
            'referer':'https://web.skype.com/en/',
            'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.96 Safari/537.36'
        }
    }, function(err, resp, body) {
        _this.requestWithJar(reqURI, {
            headers: {
                'Accept': 'application/json, text/javascript',
                'Accept-Encoding': 'gzip, deflate, br',
                'Accept-Language': 'en-US,en;q=0.8',
                'Content-Type': 'application/json',
                'Host': 'skypegraph.skype.com',
                'Origin': 'https://web.skype.com',
                'Referer': 'https://web.skype.com/en/',
                'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.96 Safari/537.36',
                'X-Skypetoken': skypeAccount.skypeToken
            }
        }, function(err, resp, body) {
            cb(JSON.parse(body));
        });
    });
}