Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solve method doesn't return id of captcha task. #23

Open
Insadem opened this issue Dec 15, 2023 · 0 comments
Open

Solve method doesn't return id of captcha task. #23

Insadem opened this issue Dec 15, 2023 · 0 comments

Comments

@Insadem
Copy link

Insadem commented Dec 15, 2023

If you call client.Solve(req), you recieve token or error.
If you have desire to report captcha task - you have to use callback parameter to receive id of each task.
Simple solution would be to return id from this method too.

My implementation of this solution:

type SolveResult struct {
	ID    string
	Token string
}

func (c *Client) Solve(req Request) (SolveResult, error) {
	if c.Callback != "" {
		_, ok := req.Params["pingback"]
		if !ok {
			// set default pingback
			req.Params["pingback"] = c.Callback
		}
	}

	pingback, hasPingback := req.Params["pingback"]
	if pingback == "" {
		delete(req.Params, "pingback")
		hasPingback = false
	}

	_, ok := req.Params["soft_id"]
	if c.SoftId != 0 && !ok {
		req.Params["soft_id"] = strconv.FormatInt(int64(c.SoftId), 10)
	}

	id, err := c.Send(req)
	if err != nil {
		return SolveResult{}, err
	}

	// don't wait for result if Callback is used
	if hasPingback {
		return SolveResult{
			ID: id,
		}, nil
	}

	timeout := c.DefaultTimeout
	if req.Params["method"] == "userrecaptcha" {
		timeout = c.RecaptchaTimeout
	}

	result, resultErr := c.WaitForResult(id, timeout, c.PollingInterval)
	return SolveResult{ID: id, Token: result}, resultErr
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant