Flask webhook that lets a Dialogflow agent play chess against Stockfish. Game state is stored in MySQL (Cloud SQL) keyed by the Dialogflow session URL.
- Dialogflow webhook endpoint for chess actions
- Stockfish-backed move generation
- Persistent games in MySQL
- Cloud Run deployment script
main.py: Flask app + Dialogflow webhook handlerschess_engine.py: Chess and Stockfish helpersentities/: Dialogflow entity definitionssql_commands/db_script.sql: database/table notesDockerfile,deploy.sh: Cloud Run container + deploy commandsstockfish_20011801_x64: bundled Stockfish binary
- Python 3.8
- MySQL (Cloud SQL)
Install deps:
pip install -r requirements.txtThe app expects Cloud SQL via a Unix socket. Set these environment variables:
DB_USERDB_PASSDB_NAMECLOUD_SQL_CONN(e.g.PROJECT:REGION:INSTANCE)DB_SOCKET_DIR(optional, default/cloudsql)PORT(for gunicorn, e.g.8080)
Dialogflow webhook handler. The request must include:
queryResult.actionqueryResult.parameterssession
Supported actions:
CreateGame: starts a new gameMakeMove: applies a user move, then plays Stockfish responseRevertMove: reverts last two pliesResignGame: deletes the session rowShowValidMoves: lists legal moves
Parameters used:
Color:white|black|randomLevel: 1-10 (Stockfish strength)ChessPiece:N,B,R,Q,Kor empty for pawnMoves: move tokens (single square or [from,to])Specialmoves:short_castle|long_castle
Responses are Dialogflow fulfillmentText strings.
The game table stores:
session_urlboard(pickled chess.Board)player_colorengine_level
See sql_commands/db_script.sql for a starter schema.
Build and deploy using the included script:
./deploy.shThis script expects Google Cloud credentials, a Cloud Run service, and Cloud SQL instance/secrets wired as shown in deploy.sh.