Hub JS Package

Hub JS Package

  • Users
  • Buckets
  • Threads
  • Textile Docs

›Users API

Users API

  • Users.getUsage() method
  • Users.setupMailbox() method
  • Users.getMailboxID() method
  • Users.sendMessage() method
  • Users.watchInbox() method
  • Users.watchSentbox() method
  • Users.listSentboxMessages() method
  • Users.deleteSentboxMessage() method
  • Users.listInboxMessages() method
  • Users.readInboxMessage() method
  • Users.deleteInboxMessage() method
  • Users.listThreads() method
  • Users.getThread() method
  • Users.copyAuth() method
  • Users.withUserAuth() method
  • Users.withKeyInfo() method
  • Users.getToken() method
  • Users.getTokenChallenge() method
  • Users.setToken() method
  • Users.withThread() method

Types

  • GetThreadResponse interface
  • InboxListOptions interface
  • MailboxEvent interface
  • MailboxEventType enum
  • PushPathResult interface
  • PushPathsResult interface
  • SentboxListOptions interface
  • UserMessage interface
  • UsageOptions interface
  • GetUsageResponse interface

Identity interfaces

  • Identity interface
  • Identity.public property
  • Identity.sign() method
  • Private interface
  • Public interface
  • Public.bytes property
  • Public.verify() method

Private Key Class

  • PrivateKey class
  • PrivateKey.bytes property
  • PrivateKey.canSign() method
  • PrivateKey.decrypt() method
  • PrivateKey.fromRandom() method
  • PrivateKey.fromString() method
  • PrivateKey.privKey property
  • PrivateKey.pubKey property
  • PrivateKey.public property
  • PrivateKey.sign() method
  • PrivateKey.seed property
  • PrivateKey.toString() method
  • PrivateKey.type property
  • PrivateKey.fromRawEd25519Seed() method

Public Key Class

  • PublicKey class
  • PublicKey.fromString() method
  • PublicKey.toString() method
  • PublicKey.verify() method
  • PublicKey.encrypt() method
  • PublicKey.bytes property
  • PublicKey.type property
  • PublicKey.pubKey property

@textile/hub > Users > watchInbox

Users.watchInbox() method

watchInbox watches the inbox for new mailbox events. Returns a listener of watch connectivity states.

Signature:

watchInbox(id: string, callback: (reply?: MailboxEvent, err?: Error) => void): grpc.Request;

Parameters

ParameterTypeDescription
idstringthe mailbox id
callback(reply?: MailboxEvent, err?: Error) => voidhandles each new mailbox event

Returns:

grpc.Request

listener. listener.close will stop watching.

Example 1

Listen and log all new inbox events

import { Users, MailboxEvent } from '@textile/hub'

const callback = async (reply?: MailboxEvent, err?: Error) => {
  if (!reply || !reply.message) return console.log('no message')
  console.log(reply.type)
}

async function example (users: Users) {
  const mailboxID = await users.getMailboxID()
  const closer = await users.watchInbox(mailboxID, callback)
  return closer
}

Example 2

Decrypt a new message in local user's inbox sent by listener callback

import { Users, MailboxEvent, PrivateKey } from '@textile/hub'

const userID = PrivateKey.fromRandom()

const callback = async (reply?: MailboxEvent, err?: Error) => {
  if (!reply || !reply.message) return console.log('no message')
  const bodyBytes = await userID.decrypt(reply.message.body)

  const decoder = new TextDecoder()
  const body = decoder.decode(bodyBytes)

  console.log(body)
}

// Requires userID already be authenticated to the Users API
async function startListener(users: Users) {
  const mailboxID = await users.getMailboxID()
  const closer = await users.watchInbox(mailboxID, callback)
}

← Users.sendMessage() methodUsers.watchSentbox() method →
  • Users.watchInbox() method
  • Parameters
  • Example 1
  • Example 2
Hub JS Package
Docs
Getting StartedThreadDBBuckets
Resources
All DocumentationProject SlackBlog
More
GitHubStar
Follow @textileio