/snapper

A Go library for easy interaction with Snapchat's Web API.

Primary LanguageGoMIT LicenseMIT

Snapper

Snapper is a lightweight, easy-to-use Go library for interacting with Snapchat's Web API.

Installation

Use the package manager to install snapper.

go get github.com/0xzer/snapper

Features

  • Fetch account information
  • Fetch information about a snapchatter
  • Fetch a users bitmoji
  • List Friends (friendmojis, streaks, display name & more!)
  • List Conversations/Groups
  • Sync/DeltaSync Conversations/Groups (Batch & Single)
  • Send typing notifications (Groups & Conversations)
  • Query messages in conversations/groups (with message history support!)
  • Update Conversations/Groups
    • Change group title
    • Mark as read
    • Leave Group
    • Change Retention Policy
    • Clear from chat feed
    • Change notification preference
    • Add participants
  • Update Messages
    • Read
    • Release
    • Save
    • Unsave
    • Erase (delete message)
    • Save to camera roll
    • Screenshot
    • Screenrecord
    • Replay
    • React
    • Remove reaction
  • Create Conversations/Groups
  • Send Messages
    • Chat text messages
    • Send to multiple conversations/groups
    • Reply to messages
    • Set save policy on each message you send
    • Snaps (coming soon!)
    • Sticker (coming soon!)
    • Share (coming soon!)
    • Note (coming soon!)
    • SnapReply (coming soon!)
    • Location (coming soon!)
  • Generate fidelius keys

Usage

  • More examples here
package main

import (
	"encoding/json"
	"log"
        "github.com/rs/zerolog"
	"github.com/0xzer/snapper"
	"github.com/0xzer/snapper/protos"
)

var cli *snapper.Client

func main() {
        cookieStr := "sc-cookies-accepted=; EssentialSession=; Preferences=; Performance=; Marketing=; __Host-X-Snap-Client-Cookie=; __Host-sc-a-session=; sc-a-nonce=; __Host-sc-a-nonce=;sc-a-csrf=; blizzard_client_id="
	sess, err := snapper.NewSessionFromCookies(cookieStr) // or snapper.NewSessionFromFile("session.json")
	if err != nil {
		log.Fatal(err)
	}

	cli = snapper.NewClient(sess, zerolog.Logger{}, nil)

	sendChatMessage()

	err = cli.SaveSession("session.json")
	if err != nil {
		log.Fatal(err)
	}
}

func sendChatMessage() {
	conversations := getExampleConversations()
	firstConversation := conversations[0]

	messageBuilder := cli.NewCreateMessageBuilder().
	AddConversationDestination(firstConversation).
	SetTextMessage("hello!").
	SetSavePolicy(protos.ContentEnvelope_SavePolicy_LIFETIME)
	
	sent, err := cli.Messaging.SendContentMessage(messageBuilder)
	if err != nil {
		log.Fatal(err)
	}

	log.Println(sent)
}

func getExampleConversations() []*protos.Conversation {
	conversationEntries, err := cli.Messaging.SyncConversations(nil, nil)
	if err != nil {
		log.Fatal(err)
	}

	conversationsBatch := cli.Messaging.BatchRequestFromEntry(conversationEntries.GetConversations())
	batchDeltaSync, err := cli.Messaging.BatchDeltaSync(conversationsBatch)
	if err != nil {
		log.Fatal(err)
	}

	return cli.Messaging.BatchResponseToConversationSlice(batchDeltaSync)
}