ifo / gozulipbot

A bot library in Go for Zulip
ISC License
17 stars 7 forks source link

[bot.RegisterEvents] criptic failure when `Unmarshal`-ing "invitation needed" html error page to json #3

Open WillForan opened 1 year ago

WillForan commented 1 year ago

The error message "invalid character '<' looking for beginning of value" was tricky for me to track down. I'm new to goland and zulip, and am likely doing something unexpected. But could this error be caught checking resp.Header["Content-Type"][0], or is there a place to add Accept: application/json to the reg request?

I'm trying to setup a single chat interface to all of my user's zulip events (a la https://github.com/Stantheman/zulip-irc-ii) and am using the api key and settings from the zulipchat.com/#settings/account-and-privacy zuliprc export. But something goes wrong at registration and unmarshal fails.

Zulip is returning html that includes the text "You need an invitation to join this organization" (a separate problem I don't understand yet)


 # zulip env from zuliprc
eval "$(sed '
   /^\[/d;                    # remove [api] header
   s:site=\(.*\):apiurl=\1/:; # site => apiurl, needs '/' at the end
   s/key/apikey/;
   s/.*=/export ZULIP_\U&/    # vars are uppercase and start with ZULIP_
 ;'  ~/Downloads/zuliprc)"

./watchevents --env

invalid character '<' looking for beginning of value

stepping through the debugger, I see body is html when I think it's expected to be json. the html contains a note about not being invited -- but at least the workspace description matches that of where my user is and is where I grabbed the api credentials.

dlv exec ./watchevents -- --env
  break /home/foranw/src/gozulipbot/bot.go:159
  continue
  config  max-array-values 10000
  p string(body)

  p resp.Header["Content-Type"][0]

... You need an invitation to join this organization ... "text/html; charset=utf-8"

WillForan commented 1 year ago

Ah I think I just need to add /api/v1/ to what I had for ZULIP_APIURL! Sorry for the rubber ducking.

sed+eval above should be s:site=\(.*\):apiurl=\1/api/v1/:

echo $ZULIP_APIURL 
https://xxxx.zulipchat.com/api/v1/