Skip to content

nordeck/intercom-presence

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

98 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Presence service with NATS

NATS server

Open https://github.com/nats-io/nats-server/releases/latest and download the matching package. e.g. nats-server-v2.10.22-linux-amd64.zip into /tmp.

cd /tmp
unzip nats-server-v2.10.22-linux-amd64.zip
cp /tmp/nats-server-v2.10.22-linux-amd64/nats-server ~/bin/

To run:

nats-server

Deno

As root

cd /tmp
wget -O deno.zip https://github.com/denoland/deno/releases/latest/download/deno-x86_64-unknown-linux-gnu.zip
unzip deno.zip
./deno --version

cp /tmp/deno /usr/local/bin/
deno --version

Presence service

In this directory:

deno --allow-net presence.ts

Intercom service

In this directory:

deno --allow-net intercom.ts

NATS CLI

Open https://github.com/nats-io/natscli/releases/latest and download the matching package. e.g. nats-0.1.5-linux-amd64.zip into /tmp

cd /tmp
unzip nats-0.1.5-linux-amd64.zip
cp /tmp/nats-0.1.5-linux-amd64/nats ~/bin/

Testing (presence)

USER1_KEYCLOAK_SUB="f:d704f61d-fade-4641-b03a-1f211206c5b6:user1"
USER2_KEYCLOAK_SUB="f:d704f61d-fade-4641-b03a-1f211206c5b6:user2"
USER3_KEYCLOAK_SUB="f:d704f61d-fade-4641-b03a-1f211206c5b6:user3"

USER1_KEYCLOAK_USERINFO=$(cat <<EOF
{
  "sub": "$USER1_KEYCLOAK_SUB",
  "email_verified": true,
  "preferred_username": "user1",
  "email": "[email protected]"
}
EOF
)

USER2_KEYCLOAK_USERINFO=$(cat <<EOF
{
  "sub": "$USER2_KEYCLOAK_SUB",
  "email_verified": false,
  "preferred_username": "user2",
  "email": "[email protected]",
  "statusVisible": false
}
EOF
)

USER3_KEYCLOAK_USERINFO=$(cat <<EOF
{
  "sub": "$USER3_KEYCLOAK_SUB",
  "email_verified": false,
  "preferred_username": "user3",
  "email": "[email protected]",
  "presenceVisible": false
}
EOF
)

nats -s "127.0.0.1" pub presence.update "$USER1_KEYCLOAK_USERINFO"
nats -s "127.0.0.1" pub presence.update "$USER2_KEYCLOAK_USERINFO"
nats -s "127.0.0.1" pub presence.update "$USER3_KEYCLOAK_USERINFO"

nats -s "127.0.0.1" req presence.all "" | jq .
nats -s "127.0.0.1" req presence.all "3600" | jq .
nats -s "127.0.0.1" req presence.online "" | jq .
nats -s "127.0.0.1" req presence.online "30" | jq .

nats -s "127.0.0.1" req presence.whoami "$USER1_KEYCLOAK_SUB" | jq .
nats -s "127.0.0.1" req presence.isonline "$USER1_KEYCLOAK_SUB"

nats -s "127.0.0.1" pub presence.ping "$USER1_KEYCLOAK_SUB"

nats -s "127.0.0.1" pub presence.hide "$USER1_KEYCLOAK_SUB"
nats -s "127.0.0.1" req presence.all "" | jq .
nats -s "127.0.0.1" pub presence.unhide "$USER1_KEYCLOAK_SUB"
nats -s "127.0.0.1" req presence.all "" | jq .

nats -s "127.0.0.1" pub presence.hide_status "$USER1_KEYCLOAK_SUB"
nats -s "127.0.0.1" req presence.online "" | jq .
nats -s "127.0.0.1" pub presence.unhide_status "$USER1_KEYCLOAK_SUB"
nats -s "127.0.0.1" req presence.online "" | jq .

Testing (notification stream)

Use scripts in UI.

Links