Challenge a bot using the API?

Hi, has anyone had any luck sending a challenge to a bot and having the bot auto accept? The following function works fine against players (I’ve tested it with a second account) but it doesn’t seem to work with a bot (I tested it with amybot-beginner), I get a game ID but when I go to it the page looks like this:
https://imgur.com/a/hKmK0Mc

I tried matching the game settings as best I could, but maybe I’m missing something specific that prevents the bot from starting the game? Thanks for any help!

def challenge_player(access_token: str, player_id: int, game_name: str) →
Union[None, Tuple[int, int]]:
url = f"https://online-go.com/api/v1/players/{player_id}/challenge/"
headers = {‘Authorization’: f"Bearer {access_token}", ‘Content-Type’: ‘application/json’}

# Initialize game portion of the request
game = {
    'name': game_name,
    'private': False,
    'rules': 'chinese',
    'ranked': False,
    'handicap': 0,
    'speed': 'correspondence',
    'time_control': 'fischer',
    "time_control_parameters": {
        'system': 'fischer',
        "time_control": "fischer",
        "initial_time": 259200,
        "max_time": 604800,
        "time_increment": 86400
    },
    'pause_on_weekends': True,
    'width': 9,
    'height': 9,
    'disable_analysis': False
}

data = {'game': game, 'challenger_color': 'automatic', 'min_ranking': -1000, 'max_ranking': 1000, 'initialized': False,
        'aga_ranked': False}

resp = requests.post(url=url, json=data, headers=headers)

if resp.status_code != 200:
    print(f"Error creating challenge: {resp.status_code} {resp.text}", file=stderr)
    return None

resp_data = resp.json()
return resp_data['challenge'], resp_data['game']

Right after submitting this post I noticed I get an empty notification when sending the request. Very interesting… though it doesn’t tell me much

I haven’t tried this myself yet, but I’d recommend sending the bot a request from the main site and examining the XHR. Maybe there will be a hint (some bots don’t accept correspondence, for example)

1 Like

Is the XHR just the game info or something more detailed? I’ve compared the request to the game information tab and everything matches, but yeah maybe I should check the SGF too to see if I’m missing something. I know it’s not correspondence causing it because I was able to get that to start if I send the request manually.

XHR = cross header request XMLHttpRequest. Basically the REST API calls.

If you open the network tab in developer tools of your browser, you should be able to look into the requests that are sent. You can also look at the websocket traffic, which might help too.

Basically you’d be looking at what gets sent to the server when you create a game with a bot. Maybe the web client sends a special flag that we are missing!

Edit: oops I really need to look acronyms up before I try to define them

2 Likes

Got it to work! I followed your advice and matched my request data as best I could, I’m honestly still not sure what was the issue (I should go back and try line by line to see what this issue was) but yes, I can confirm this works now. It may be bot specific, as I tried sending the same request to a different one and it failed as before, so maybe you’ll need to tailor each request to the bot in question. Appreciate your help!

2 Likes

Are you going to be challenging the bots from an alternate client?

1 Like

Technically yes, I’m building a 9x9 board and planning on interfacing with OGS so I can send and receive moves straight to the board (it’ll have an LED matrix on the bottom as well). Being able to challenge bots directly will be really nice, one less thing to have to setup prior to using it (the interface will be pretty bare bones, so challenging actual people will probably be best done on the website beforehand)

1 Like

Wow super cool, keep us posted on the progress!