Skip to content

Converting from image/gif/videos on whatsapp to a sticker by using a caption in a chat where the bot is present

License

Notifications You must be signed in to change notification settings

deven96/whatsticker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Whatsticker

mythra

A Whatsapp bot that turns pictures, small videos and gifs into stickers with the caption stickerize deven96

Usage

Requirements

Generating Credentials

  • Download Go modules

    # Downloads go modules
    go mod tidy
  • Run go run main.go to show qr code for login on terminal

    Example QR Code

  • Link device as explained on WhatsApp FAQ

A folder db/ will be automatically created containing sqlite db with credentials. No need to login over and over except logged out on main device. You can copy this folder to target machine and it still works

Running The Bot

  • Ensure db/examplestore.db exists and run docker-compose up
  • Open any chat (Personal/Group) where the logged in number is present
  • Send media with caption and number should respond with sticker

Example response

WARNING: db/ folder on root will contain examplestore.db which docker-compose expects to load as a volume. Do not create a public image using this folder or commit to version control as it can be used to impersonate you

CLI Flags

The following flags are available

  • -log-level : To switch between log verbosity between INFO and DEBUG
  • -reply-to : Set to true if bot should quote original messages with reply

Flow

|├── handler                         # Contains logic for running sticker procedure on images/video
|    |___ handler.go
|    |___ image.go
|    |___ video.go
|
|├── LICENSE
|├── main.go                         # Login to WA client and sets up event handler
|└── README.md
  • Initializes WA client (new credentials in db or uses existing)
  • Sets up eventHandler to monitor all incoming events and passes WA client to media handler handler.Run()
  • Four possible messages trigger the core media handler
    • Image with caption
    • Video with caption
    • GIF with caption
    • Text matching correct caption that quotes an image/video/gif ( media type and content gets set to quoted media)
  • One of either Handler gets initialized based on media type
  • Handler has some methods that get run
    • SetUp : set client to WA client, reply to option and create folders for media if not exist
    • Validate: enforce some constraints on media size/length
    • Handle: Downloads the raw media -> Converts media to webP (as WhatsApp stickers are wrappers around webp images) using the specified codec -> Uploads it to WA -> Return a sticker message
    • SendResponse: Sends sticker to originating chat
    • CleanUp: Remove raw and converted media from file system

Limits/Issues

  • Media sizes/length enforced by code
  • Some sticker results for videos are not animated (WebP size exceeds 1MB)
  • Sometimes original media cannot be downloaded (especially for quoting older media messages with caption)
  • reply-to flag causes iOS users to be incorrectly tagged

License

This project is opened under the MIT License which allows very broad use for both academic and commercial purposes

Credits

Library/Resource Use
tulir/whatsmeow whatsmeow is a Go library for the WhatsApp web multidevice API.
ffmpeg A complete cross platform solution to record, convert and stream video (and audio).
cwebp Compress an image file into WebP file

About

Converting from image/gif/videos on whatsapp to a sticker by using a caption in a chat where the bot is present

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project