// test account (avicious.406+test@gmail.com) API key // eZbV6TDcl2qUmtEAMLllN8qOHeb1hQiS8sVEoG2OmfqLym4UqihiFL83xgM2SLGPtz8HS2DeX45sk89B // test offer id: https://hhtestnet.com/offers/F8W2srPJK2JKwYdh // TODO: unmarshal json (encoding/json) package main import ( "fmt" "log" "os" "net/http" "io/ioutil" "encoding/json" "errors" "gosrc.io/xmpp" "gosrc.io/xmpp/stanza" ) const ( // APIEndpoint = "https://hodlhodl.com/api/v1" TestAPIEndpoint = "https://hhtestnet.com/api/v1" APIkey = "***REMOVED***" ) var ( CorrespChan = make(chan string, 1) textChan = make(chan string, 5) rawTextChan = make(chan string, 5) killChan = make(chan error, 1) errChan = make(chan error) rosterChan = make(chan struct{}) logger *log.Logger disconnectErr = errors.New("disconnecting client") ) // Notification export type Notification struct { Status string `json:"status"` Notifications []struct { ID string `json:"id"` Title string `json:"title"` Body string `json:"body"` Link string `json:"link"` } `json:"notifications"` } type config struct { Server map[string]string `mapstructure:"server"` Client map[string]string `mapstructure:"client"` Contacts string `string:"contact"` LogStanzas map[string]string `mapstructure:"logstanzas"` } func gethdlNotif() { req, err := http.NewRequest("POST", TestAPIEndpoint + "/notifications/read", nil) if err != nil { fmt.Println(err) } req.Header.Add("Authorization", "Bearer " + APIkey) req.Header.Set("Content-Type", "application/json") resp, err := http.DefaultClient.Do(req) if err!= nil { fmt.Println(err) } fmt.Println(resp.Status) body, err := ioutil.ReadAll(resp.Body) if err != nil { fmt.Println(err) } else { res:= Notification{} json.Unmarshal([]byte(body), &res) fmt.Println("RESULT", res) fmt.Println("RESULTAT", string(body)) } defer resp.Body.Close() } func handleMessage(s xmpp.Sender, p stanza.Packet) { msg, ok := p.(stanza.Message) if !ok { _, _ = fmt.Fprintf(os.Stdout, "Ignoring packet: %T\n", p) return } _, _ = fmt.Fprintf(os.Stdout, "Body = %s - from = %s\n", msg.Body, msg.From) reply := stanza.Message{Attrs: stanza.Attrs{To: msg.From}, Body: msg.Body} _ = s.Send(reply) } func startClient() { // Client Setup clientCfg := &xmpp.Config { TransportConfiguration: xmpp.TransportConfiguration{ Address: "xmpp.sp4ke.xyz", }, Jid: "vicious@xmpp.sp4ke.xyz", Credential: xmpp.Password("***REMOVED***"), Insecure: true, } var err error router := xmpp.NewRouter() handleMessage := func(s xmpp.Sender, p stanza.Packet) { msg, ok := p.(stanza.Message) if !ok { _, _ = fmt.Fprintf(os.Stdout, "Ignoring packet: %T\n", p) return } _, _ = fmt.Fprintf(os.Stdout, "Body = %s - from = %s\n", msg.Body, msg.From) reply := stanza.Message{Attrs: stanza.Attrs{To: msg.From}, Body: msg.Body} _ = s.Send(reply) } errorHandler:= func(err error) { fmt.Println(err.Error()) } router.HandleFunc("HELLO TEST", handleMessage) client, err := xmpp.NewClient(clientCfg, router, errorHandler) if err != nil { log.Panicln(fmt.Sprintf("Could not create a new client ! %s", err)) //log.Fatalf("%+v", err) } else { fmt.Println("Client running....") } // Connection manager, reconect automatically cm := xmpp.NewStreamManager(client, nil) log.Fatal(cm.Run()) } /*func startMessaging(client xmpp.Sender, config *config) { var text string var correspondent string for { select { case err := <-killChan: if err == disconnectErr { sc := client.(xmpp.StreamClient) sc.Disconnect() } else { logger.Println(err) } return case text = <-textChan: reply := stanza.Message{Attrs: stanza.Attrs{To: correspondent, Type: stanza.MessageTypeChat}, Body: text} if logger != nil { raw, _ := xml.Marshal(reply) logger.Println(string(raw)) } err := client.Send(reply) if err != nil { fmt.Printf("There was a problem sending the message : %v", reply) return } case text = <-rawTextChan: if logger != nil { logger.Println(text) } err := client.SendRaw(text) if err != nil { fmt.Printf("There was a problem sending the message : %v", text) return } case crrsp := <-CorrespChan: correspondent = crrsp case <-rosterChan: askForRoster(client, g, config) } } }*/ func main() { //body:= strings.NewReader(' -X POST -H "Authorization: Bearer ***REMOVED***" -H "Content-Type: application/json"`) // Read configuration startClient() }