Crawlee—A web scraping and browser automation library for Node.js to build reliable crawlers. In JavaScript and TypeScript. Extract data for AI, LLMs, RAG, or GPTs. Download HTML, PDF, JPG, PNG, and other files from websites. Works with Puppeteer, Playwright, Cheerio, JSDOM, and raw HTTP. Both headful and headless mode. With proxy rotation.
TypeScript apifyautomationcrawlercrawlingheadlessheadless-chromejavascriptnodejsnpmplaywrightpuppeteerscraperscrapingtypescriptweb-crawlerweb-crawlingweb-scraping
Adding missing webhooks param to call() and callTask()
Marek Trunkatbe54c26b10fa
diff --git a/src/actor.js b/src/actor.jsindex dd04b7630..24d064618 100644--- a/src/actor.js+++ b/src/actor.js@@ -339,6 +339,9 @@ let callMemoryWarningIssued = false;* @param {Boolean} [options.disableBodyParser=false]* If `true` then the function will not attempt to parse the* actor's output and will return it in a raw `Buffer`.+ * @param {Array} [options.webhooks] Specifies optional webhooks associated with the actor run, which can be used+ * to receive a notification e.g. when the actor finished or failed, see+ * [ad hook webhooks documentation](https://apify.com/docs/webhooks#adhoc) for detailed description.* @returns {Promise<ActorRun>}* @throws {ApifyCallError} If the run did not succeed, e.g. if it failed or timed out.*@@ -357,7 +360,7 @@ export const call = async (actId, input, options = {}) => {checkParamOrThrow(token, 'token', 'Maybe String');// RunAct() options.- const { build, memory, timeoutSecs } = options;+ const { build, memory, timeoutSecs, webhooks } = options;let { memoryMbytes } = options;const runActOpts = {actId,@@ -376,10 +379,12 @@ export const call = async (actId, input, options = {}) => {checkParamOrThrow(build, 'build', 'Maybe String');checkParamOrThrow(memoryMbytes, 'memoryMbytes', 'Maybe Number');checkParamOrThrow(timeoutSecs, 'timeoutSecs', 'Maybe Number');+ checkParamOrThrow(webhooks, 'webhooks', 'Maybe Array');if (token) runActOpts.token = token;if (build) runActOpts.build = build;if (memoryMbytes) runActOpts.memory = memoryMbytes;if (timeoutSecs >= 0) runActOpts.timeout = timeoutSecs; // Zero is valid value!+ if (webhooks) runActOpts.webhooks = webhooks;if (input) addInputOptionsOrThrow(input, options.contentType, runActOpts);// Run actor.@@ -470,6 +475,9 @@ export const call = async (actId, input, options = {}) => {* If the limit is reached, the returned promise is resolved to a run object that will have* status `READY` or `RUNNING` and it will not contain the actor run output.* If `waitSecs` is null or undefined, the function waits for the actor task to finish (default behavior).+ * @param {Array} [options.webhooks] Specifies optional webhooks associated with the actor run, which can be used+ * to receive a notification e.g. when the actor finished or failed, see+ * [ad hook webhooks documentation](https://apify.com/docs/webhooks#adhoc) for detailed description.* @returns {Promise<ActorRun>}* @throws {ApifyCallError} If the run did not succeed, e.g. if it failed or timed out.*@@ -488,15 +496,17 @@ export const callTask = async (taskId, input, options = {}) => {checkParamOrThrow(token, 'token', 'Maybe String');// Run task options.- const { build, memoryMbytes, timeoutSecs } = options;+ const { build, memoryMbytes, timeoutSecs, webhooks } = options;const runTaskOpts = { taskId };checkParamOrThrow(build, 'build', 'Maybe String');checkParamOrThrow(memoryMbytes, 'memoryMbytes', 'Maybe Number');checkParamOrThrow(timeoutSecs, 'timeoutSecs', 'Maybe Number');+ checkParamOrThrow(webhooks, 'webhooks', 'Maybe Array');if (token) runTaskOpts.token = token;if (build) runTaskOpts.build = build;if (memoryMbytes) runTaskOpts.memory = memoryMbytes;if (timeoutSecs >= 0) runTaskOpts.timeout = timeoutSecs; // Zero is valid value!+ if (webhooks) runTaskOpts.webhooks = webhooks;if (input) addInputOptionsOrThrow(input, options.contentType, runTaskOpts);// Start task.diff --git a/test/actor.js b/test/actor.jsindex adfc758b1..35f4cde6a 100644--- a/test/actor.js+++ b/test/actor.js@@ -246,6 +246,7 @@ describe('Apify.call()', () => {const build = 'xxx';const memoryMbytes = 1024;const timeoutSecs = 60;+ const webhooks = ['a', 'b'];const actsMock = sinon.mock(Apify.client.acts);actsMock.expects('runAct')@@ -257,6 +258,7 @@ describe('Apify.call()', () => {build,memory: memoryMbytes,timeout: timeoutSecs,+ webhooks,}).once().returns(Promise.resolve(runningRun));@@ -276,7 +278,7 @@ describe('Apify.call()', () => {.returns(Promise.resolve(output));return Apify- .call(actId, input, { contentType, token, disableBodyParser: true, build, memoryMbytes, timeoutSecs })+ .call(actId, input, { contentType, token, disableBodyParser: true, build, memoryMbytes, timeoutSecs, webhooks }).then((callOutput) => {expect(callOutput).to.be.eql(expected);keyValueStoresMock.restore();@@ -711,6 +713,7 @@ describe('Apify.callTask()', () => {const memoryMbytes = 256;const timeoutSecs = 60;const build = 'beta';+ const webhooks = ['a', 'b'];const tasksMock = sinon.mock(Apify.client.tasks);tasksMock.expects('runTask')@@ -722,6 +725,7 @@ describe('Apify.callTask()', () => {memory: memoryMbytes,timeout: timeoutSecs,build,+ webhooks,}).once().returns(Promise.resolve(runningRun));@@ -743,7 +747,7 @@ describe('Apify.callTask()', () => {.returns(Promise.resolve(output));return Apify- .callTask(taskId, input, { token, disableBodyParser: true, memoryMbytes, timeoutSecs, build })+ .callTask(taskId, input, { token, disableBodyParser: true, memoryMbytes, timeoutSecs, build, webhooks }).then((callOutput) => {expect(callOutput).to.be.eql(expected);keyValueStoresMock.restore();