The identifier of the subtask being handled
The complete response from the previous authentication flow step
The user's authentication credentials including username, password, etc.
An interface providing methods to interact with the authentication flow
A promise resolving to either a successful flow response or an error
import { Scraper, FlowSubtaskHandler } from "@the-convocation/twitter-scraper";
// Custom handler for a hypothetical verification subtask
const verificationHandler: FlowSubtaskHandler = async (
subtaskId,
response,
credentials,
api
) => {
// Extract the verification data from the response
const verificationData = response.subtasks?.[0].exampleData?.value;
if (!verificationData) {
return {
status: 'error',
err: new Error('No verification data found in response')
};
}
// Process the verification data somehow
const result = await processVerification(verificationData);
// Submit the result using the flow API
return await api.sendFlowRequest({
flow_token: api.getFlowToken(),
subtask_inputs: [{
subtask_id: subtaskId,
example_verification: {
value: result,
link: "next_link"
}
}]
});
};
const scraper = new Scraper();
scraper.registerAuthSubtaskHandler("ExampleVerificationSubtask", verificationHandler);
// Later, when logging in...
await scraper.login("username", "password");
A handler function for processing Twitter authentication flow subtasks. Library consumers can implement and register custom handlers for new or existing subtask types using the Scraper.registerAuthSubtaskHandler method.
Each subtask handler is called when its corresponding subtask ID is encountered during the authentication flow. The handler receives the subtask ID, the previous response data, the user's credentials, and an API interface for interacting with the authentication flow.
Handlers should process their specific subtask and return either a successful response or an error. Success responses typically lead to the next subtask in the flow, while errors will halt the authentication process.