A golang package to communicate with HipChat over XMPP

Overview

hipchat

This is a abstraction in golang to Hipchat's implementation of XMPP. It communicates over TLS and requires zero knowledge of XML or the XMPP protocol.

bot building

Hipchat treats the "bot" resource differently from any other resource connected to their service. When connecting to Hipchat with a resource of "bot", a chat history will not be sent. Any other resource will receive a chat history.

example/hello.go

package main

import (
	"github.com/daneharrigan/hipchat"
)

func main() {
	user := "11111_22222"
	pass := "secret"
	resource := "bot"
	roomJid := "[email protected]"
	fullName := "Some Bot"

	client, err := hipchat.NewClient(user, pass, resource)
	if err != nil {
		fmt.Printf("client error: %s\n", err)
		return
	}

	client.Status("chat")
	client.Join(roomJid, fullName)
	client.Say(roomJid, fullName, "Hello")
	select {}
}
Issues
  • Add a channel for unsupported xmpp event types

    Add a channel for unsupported xmpp event types

    In the process of troubleshooting issues with dying connections I made the change for configurable KeepAlives. When that still didn't solve the problem, I added a new channel for unhandled events as well as changing the way keep alives are done to use the documented mechanism for pings here:

    https://ecosystem.atlassian.net/wiki/display/HCDEV/HipChat+XMPP+Protocol+Documentation#HipChatXMPPProtocolDocumentation-Pings (the XEP-0198 implementation)

    Instead of creating a specific channel for acks, I just used the new channel so my upstream application could handle them.

    opened by lusis 4
  • Allow configuration of client domain for Hipchat Server

    Allow configuration of client domain for Hipchat Server

    Quick PR to fix #20

    There are probably more elegant ways to fix this, like having a more generic 'xmppDomain' parameter to NewClientWithServerInfo() with a default of 'hipchat.com' and then defining clientDomain like

    "chat." + xmppDomain

    and mucDomain like

    "conf." + xmppDomain

    Let me know what you think.

    opened by hrak 3
  • Cannot filter out old messages when joining a room

    Cannot filter out old messages when joining a room

    Upon joining a room, HipChat sends a dump of the room's recent history, which I want to filter out. This library does not expose any timestamp data (which I assume hipchat provides for these history messages). And I can't seem to connect as a bot by joining rooms with a JID of "bot" as per this support page.

    opened by tune-george 3
  • implement PrivSay to send private messages

    implement PrivSay to send private messages

    Private messages are 1-1 messages between two parties, using an XMPP type of 'chat'. In order to retain full backwards compatibility, this commit adds the new function 'PrivSay' rather than changing the 'Say' function to require an additional flag.

    opened by jschauma 2
  • Receiving unsolicited xmpp.NsDisco or xmpp.NsIqRoster will block listen function

    Receiving unsolicited xmpp.NsDisco or xmpp.NsIqRoster will block listen function

    This problem can be reproduced by connecting to hipchat and changing the name of a user.

    The receivedRooms and receivedUsers channels are unbuffered, so sending data to this channel will block until something receives from this channel. The only time these channels are received from are in the Users() and Rooms() methods.

    However, these messages generate a request so would still leave the listen thread blocked. We exposed the channels and used a goroutine similar to this to avoid the endless block. Note: Rooms() and Users() in this example just return the channels and don't make requests (the same as Messages()).

    go func() {
        for {
            select {
            case message := <-client.Messages():
                log.Printf("Received message: %v", message)
            case rooms := <-client.Rooms():
                log.Printf("Received rooms: %v", rooms)
            case users := <-client.Users():
                log.Printf("Received users: %v", users)
            }
        }
    }()
    

    Obviously there still needs to be work done to communicate received rooms and users to other goroutines, but this is one way to avoid the problem.

    opened by fedyakin 2
  • Timeout after nickname change

    Timeout after nickname change

    While in the reply example you are listening to the incoming messages and someone changes his nickname via the web interface the connection will time out and the bot will shortly disconnect.

    It only happens in this scenario.

    opened by gvisniuc 2
  • XML escape password string

    XML escape password string

    Passwords containing Predefined XML entities should be escaped when used during auth.

    Before

    <iq type='set' id='1234567890'><query xmlns='jabber:iq:auth'><username>12345_67890</username><password>Foob&R</password><resource>bot</resource></query></iq>
    client error: read: connection reset by peer
    

    After

    <iq type='set' id='1234567890'><query xmlns='jabber:iq:auth'><username>12345_67890</username><password>Foob&amp;R</password><resource>bot</resource></query></iq>
    
    opened by dacamp 1
  • Update channel handling to be non-blocking

    Update channel handling to be non-blocking

    This is a PR to fix the issue discussed in #8. We've been using the code with these changes for a couple weeks now and none of our bots are hanging like they used to.

    I also updated the examples to be use the channels instead, as @fedyakin shows in the above issue, a normal structure would probably look something like this:

    go func() {
        for {
            select {
            case message := <-client.Messages():
                log.Printf("Received message: %v", message)
            case rooms := <-client.Rooms():
                log.Printf("Received rooms: %v", rooms)
            case users := <-client.Users():
                log.Printf("Received users: %v", users)
            }
        }
    }()
    

    Let me know if you have any question.

    opened by cjhubert 1
  • Ability to receive and send private messages

    Ability to receive and send private messages

    This adds the ability to receive and send private messages.

    Received private messages are added onto the Messages channel, so the user implementing it will need to parse the message.From themselves to check whether it was from a room or from a user.

    When sending a message, it will check if the to address contains the text @chat.hipchat.com. This means that we're sending it to a user instead of a room (which would be @conf.hipchat.com), and changes the message type of the xml accordingly.

    opened by cjhubert 1
  • Client JID domain != host when using Hipchat Server

    Client JID domain != host when using Hipchat Server

    When using Hipchat Server (on-prem Hipchat) the client domain is not the same as the hostname of the server. Currently this client assumes a JID of [email protected]

    Example scenario with Hipchat Server:

    Hostname: hipchat.example.com
    Username: 1_1
    Client JID: [email protected]
    MUC domain: conf.btf.hipchat.com
    

    (Note the ".btf" bit which is also different from 'normal' Hipchat.)

    This breaks things like requesting the roster etc.

    opened by hrak 0
  • Support HipChat 2.0.0 build 2.0.7

    Support HipChat 2.0.0 build 2.0.7

    It seems that the XMPP interface at port 5222/5223 will be closed with newer HipChat server versions. Is der any idea how to support this change?

    https://confluence.atlassian.com/hc/hipchat-server-release-notes-608731400.html

    opened by eloo 3
  • Certificate issue

    Certificate issue

    Hi, i'm trying to use your library to connect to a self hosted hipchat instance and facing a problem with the TLS connection. I'm everytime getting the following error: client error: x509: certificate has expired or is not yet valid So it seems that the certificate is expired but I want to connect anyway. So how can I disable the Cert verify? Thanks

    opened by eloo 2
  • Add function for keep alive with arbitrary duration

    Add function for keep alive with arbitrary duration

    Hello,

    Duration of KeepAlive() is hard-coded so we cannot change that. Accordingly, I added a new function KeepAliveBy(sec time.Duration) to configure duration.

    Related: #12

    opened by moznion 1
Owner
Dane Harrigan
Day job account of @dane. Currently @hashicorp. Previously @heroku.
Dane Harrigan
Every 10 minutes, memory, cpu and storage usage is checked and if they over 80%, sending alert via email.

linux-alert Every 10 minutes, memory, cpu and storage usage is checked and if they over 80%, sending alert via email. Usage Create .env file from .env

Meliksah Cetinkaya 0 Feb 6, 2022
A Go (golang) package providing high-performance asynchronous logging, message filtering by severity and category, and multiple message targets.

ozzo-log Other languages 简体中文 Русский Description ozzo-log is a Go package providing enhanced logging support for Go programs. It has the following fe

Ozzo Framework 118 Jan 11, 2022
Peimports - based on golang's debug/pe this package gives quick access to the ordered imports of pe files with ordinal support

This code is almost entirely derived from the Go standard library's debug/pe package. It didn't provide access to ordinal based entries in the IAT and

Mike Wiacek 0 Jan 5, 2022
Package httpretty prints the HTTP requests you make with Go pretty on your terminal.

httpretty Package httpretty prints the HTTP requests of your Go programs pretty on your terminal screen. It is mostly inspired in curl's --verbose mod

Henrique Vicente 268 Jul 31, 2022
Structured logging package for Go.

Package log implements a simple structured logging API inspired by Logrus, designed with centralization in mind. Read more on Medium. Handlers apexlog

Apex 1.2k Jul 19, 2022
lumberjack is a log rolling package for Go

lumberjack Lumberjack is a Go package for writing logs to rolling files. Package lumberjack provides a rolling logger. Note that this is v2.0 of lumbe

Nate Finch 3.5k Aug 4, 2022
Go package for reading from continously updated files (tail -f)

Go package for tail-ing files A Go package striving to emulate the features of the BSD tail program. t, err := tail.TailFile("/var/log/nginx.log", tai

HPE Helion 2.4k Aug 10, 2022
With this package you can create your own syslog server with your own handlers for different kind of syslog messages

Using this library you can easy implement your own syslog server that: Can listen on multiple UDP ports and unix domain sockets. Can pass parsed syslo

Michał Derkacz 68 Dec 15, 2021
Package zaperations provides a Google Cloud operations suite (formerly Stackdriver) compatible config for the uber-go/zap logger.

Package zaperations provides a Google Cloud Operations (formerly Stackdriver) compatible config for the excellent uber-go/zap logger. Example This exa

Wayne 0 Nov 6, 2021
Lumberjack is a Go package for writing logs to rolling files.

Lumberjack is a Go package for writing logs to rolling files.

Go微服务 4 Feb 24, 2022
Package logging implements a logging infrastructure for Go

Golang logging library Package logging implements a logging infrastructure for Go. Its output format is customizable and supports different logging ba

Luke Zhang 0 Nov 10, 2021
Package for easy logging to logstash http input from microservices

Micro Logger package for easy logging to logstash http input from microservices

null 0 Dec 28, 2021
Print build info from binary, using buildinfo package.

Go Build Info Print build info from binary, using buildinfo package. https://pkg.go.dev/debug/[email protected] Note: This was created to help me

null 0 Dec 30, 2021
This package enables json output, level logging and so on to standard go logger.

logplug This package enables json output, level logging and so on to standard logger. Usage log.SetOutput(logplug.NewJSONPlug(os.Stderr, logplug.LogF

Koumei Mikuni 0 Dec 27, 2021
Filez - A tiny package showing you File info

filez A tiny package showing you File info Install go get -v github.com/Cne3Rd/f

Mukaila Samsondeen 1 Feb 4, 2022
Felix Geisendörfer 28 Feb 9, 2022
Errr - Errr (The Rich Structured Error Package missing from Go)

The errr package was created to fill the gap between error handling and error reporting.

Hamed Momeni 2 Feb 7, 2022
Simple and blazing fast lockfree logging library for golang

glg is simple golang logging library Requirement Go 1.11 Installation go get github.com/kpango/glg Example package main import ( "net/http" "time"

Yusuke Kato 168 Jul 27, 2022
Logging library for Golang

GLO Logging library for Golang Inspired by Monolog for PHP, severity levels are identical Install go get github.com/lajosbencz/glo Severity levels Deb

Lajos Bencz 14 Aug 26, 2021