3

The Stack Exchange chat network does not currently have an API. However, after spending a bit of time in Chrome's Inspector, I was able to reverse-engineer most of the requests and responses travelling back and forth between client and server.

This package is the result of that effort.

Basic Usage

You will need access to an account that uses Stack Exchange credentials (email and password). Other forms of authentication are not yet supported. For simplicity, the examples below do not demonstrate proper error handling.

Import the package:

import "github.com/nathan-osman/go-sechat"

Create a new Conn object, representing a connection to the chat server:

c, _ := sechat.New("email@example.com", "passw0rd", 1)

* the third parameter is the initial room to join

Since authentication and connection are done asynchronously, waiting for them to complete is highly recommended:

if !c.WaitForConnected() {
    // yell, kick, and scream
}

Join the room with ID 201:

c.Join(201)

Post a message in the room:

c.Send(201, "Testing go-sechat...")

Process all direct replies:

for e := range c.Events {
    if e.IsMention {
        log.Println(e.Content)
    }
}

Create a new room with a particular user:

roomId, _ := c.NewRoomWithUser(1234, "Room Name")

Close the connection:

c.Close()

Documentation

You can learn more about the package by visiting its documentation page:
https://godoc.org/github.com/nathan-osman/go-sechat

Source Code

The source code is released under the MIT license and can be viewed here:
https://github.com/nathan-osman/go-sechat

You must log in to answer this question.

Browse other questions tagged .