Skip to content

fix: Update whatsmeow API calls & switch to pure-Go SQLite driver - #295

Open
malganis35 wants to merge 1 commit into
lharries:mainfrom
malganis35:fix_packages
Open

fix: Update whatsmeow API calls & switch to pure-Go SQLite driver#295
malganis35 wants to merge 1 commit into
lharries:mainfrom
malganis35:fix_packages

Conversation

@malganis35

Copy link
Copy Markdown

PR: Update whatsmeow API calls & switch to pure-Go SQLite driver

Description

This pull request updates the whatsmeow client library method calls in whatsapp-bridge/main.go to conform to modern, context-aware API signatures. In addition, it migrates the project's SQLite driver from the CGO-dependent mattn/go-sqlite3 to the pure-Go glebarez/go-sqlite to allow seamless compilation on environments without a local C toolchain (e.g., Windows without GCC).


Why these changes are necessary

1. Modern Handshake and Context Requirements

Recent updates to the whatsmeow and sqlstore packages deprecate older signature variants in favor of context-aware methods. Passing context.Background() to these functions ensures that operations are cancellable, leak-proof, and compliant with the latest library conventions.

2. CGO-Free Build Support

The github.com/mattn/go-sqlite3 library requires CGO enabled, which demands a local GCC compiler. This makes running the bridge difficult on standard Windows systems without setting up MSYS2 or MinGW. Switching to github.com/glebarez/go-sqlite (which wraps modernc.org/sqlite) removes the CGO compiler dependency while maintaining fully compatible SQLite dialect operations.


Proposed Changes

API Signature Patches (main.go)

Passes context.Background() as the first parameter to:

  • client.Download (inside downloadMedia)
  • sqlstore.New (inside main)
  • container.GetFirstDevice (inside main)
  • client.GetGroupInfo (inside GetChatName)
  • client.Store.Contacts.GetContact (inside GetChatName)

Database Driver Migration

  • Imports: Swapped github.com/mattn/go-sqlite3 with github.com/glebarez/go-sqlite in main.go.
  • Driver Dialect: Changed the driver key inside sql.Open and sqlstore.New from "sqlite3" to "sqlite".
  • Connection Parameters: Changed query parameters from ?_foreign_keys=on to ?_pragma=foreign_keys(1). The pure-Go SQLite driver parses and applies connection-level PRAGMAs using this format, ensuring that foreign keys constraint checks remain fully active.
  • Module Dependencies: Updated go.mod and go.sum to track the new dependencies.

How to Test and Verify

  1. Disable CGO in your environment (if a C compiler is present) to verify a pure-Go build:
    $env:CGO_ENABLED=0
  2. Run the bridge application:
    go run .
  3. Expected output:
    • The application should compile without throwing GCC missing errors.
    • The DB connection should successfully initialize and apply database migrations.
    • The client should output the QR terminal code to authenticate with WhatsApp.

Risk / Impact Assessment

  • Database Schema: Safe. The database tables, structures, and indices remain identical.
  • Compatibility: High. Tested under go 1.25 and compiles seamlessly with zero CGO dependencies.

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

Successfully merging this pull request may close these issues.

1 participant