function makeRequest(path, options) { options = options || {}; options.uri = url.resolve(server, path); options.timeout = 1000 * 60 * 2; // 2 Minutes return request(options); }
function sendWebHookRequest(port, path, options = {}) { assert.ok(port); assert.ok(path); const protocol = options.https ? 'https' : 'http'; const url = `${protocol}://127.0.0.1:${port}${path}`; return request({ url, method: options.method || 'POST', body: options.update || { update_id: 1, message: options.message || { text: 'test' } }, json: (typeof options.json === 'undefined') ? true : options.json, }); }
// Matches /audio bot.onText(/\/audio/, function onAudioText(msg) { // From HTTP request const url = 'https://upload.wikimedia.org/wikipedia/commons/c/c8/Example.ogg'; const audio = request(url); bot.sendAudio(msg.chat.id, audio); });
schnackEvents.on('new-comment', event => { try { const post_url = config.get('page_url').replace('%SLUG%', event.slug) + '#comment-' + event.id; const comment = event.comment .split(/\n+/) .map(s => (s ? `> _${s}_` : '>')) .join('\n>\n'); const text = `A <${post_url}|new comment> was posted by ${event.user.display_name || event.user.name} under *${event.slug}*:\n\n${comment}`; request({ url: notify.slack.webhook_url, method: 'post', json: true, body: { text } }); } catch (error) { console.error('Error sending slack notification:', error); } });
const getAllOrders = async () => { const requestOptions = { method: 'POST', uri: graphqlEndpoint, body: { query: graphqlQuery, variables: { limit: graphqlPageSize, offset: 0 } }, json: true }; let allOrders = []; // Handling pagination if necessary (2 pages for ~1400 results in May 2019) // eslint-disable-next-line while (true) { const result = await request(requestOptions); const orders = result.data.account.orders.nodes; allOrders = [...allOrders, ...orders]; requestOptions.body.variables.offset += graphqlPageSize; if (orders.length < graphqlPageSize) { return allOrders; } } }
const readAPI = function (uri) { let promise = new AV.Promise() let client = http if (/^https:\/\//.test(uri)) { client = https } else if (!/^http:\/\//.test(uri)){ promise.reject(ERROR_CODE[1]) return promise } request({ url: uri, json: true }, (err, response, data) => { if (!err && response.statusCode === 200) { promise.resolve(data) } else { promise.reject(ERROR_CODE[6]) } }) return promise }
describe('#setChatPhoto', function setChatPhotoSuite() { this.timeout(timeout); before(function before() { utils.handleRatelimit(bot, 'setChatPhoto', this); }); it('should set a chat photo from file', function test() { const photo = `${__dirname}/data/chat_photo.png`; return bot.setChatPhoto(GROUPID, photo).then(resp => { assert.equal(resp, true); }); }); it('should set a chat photo from fs.readStream', function test() { const photo = fs.createReadStream(`${__dirname}/data/chat_photo.png`); return bot.setChatPhoto(GROUPID, photo).then(resp => { assert.equal(resp, true); }); }); it('should set a chat photo from request Stream', function test() { const photo = request(`${staticUrl}/chat_photo.png`); return bot.setChatPhoto(GROUPID, photo).then(resp => { assert.equal(resp, true); }); }); it('should set a chat photo from a Buffer', function test() { const photo = fs.readFileSync(`${__dirname}/data/chat_photo.png`); return bot.setChatPhoto(GROUPID, photo).then(resp => { assert.equal(resp, true); }); }); });
}); request(url) .then(async content => { const body = processReadme(content, { source: url });
}); it('should send a video from request Stream', function test() { const video = request(`${staticUrl}/video.mp4`); return bot.sendVideo(USERID, video).then(resp => { assert.ok(is.object(resp));
}); it('should send a photo from request Stream', function test() { const photo = request(`${staticUrl}/photo.png`); return bot.sendPhoto(USERID, photo).then(resp => { assert.ok(is.object(resp));
}); it('should send a sticker from request Stream', function test() { const sticker = request(`${staticUrl}/sticker.webp`); return bot.sendSticker(USERID, sticker).then(resp => { assert.ok(is.object(resp));
}); it('should send a voice from request Stream', function test() { const voice = request(`${staticUrl}/voice.ogg`); return bot.sendVoice(USERID, voice).then(resp => { assert.ok(is.object(resp));
}); it('should send an audio from request Stream', function test() { const audio = request(`${staticUrl}/audio.mp3`); return bot.sendAudio(USERID, audio).then(resp => { assert.ok(is.object(resp));
}); it('should send a document from request Stream', function test() { const document = request(`${staticUrl}/photo.gif`); return bot.sendDocument(USERID, document).then(resp => { assert.ok(is.object(resp));