PowerKeys Scripting API
    Preparing search index...

    Interface ChannelAPI

    interface ChannelAPI {
        Open(): Promise<ChannelHandle>;
        Send(channelId: string, data: string): Promise<void>;
        OnMessage(
            callback: EventCallback<
                [
                    message: {
                        channelId: string;
                        messageId: string;
                        sender: { memberId: string; connectionId: string };
                        source: "channel";
                        sentAt: string;
                        data: string;
                    },
                ],
            >,
        ): void;
        Close(channelId: string): void;
    }
    Index
    • Opens a live encrypted room channel.

      PowerKeys opens a trusted create, join, or saved-pairing prompt. Pairing codes and key material never enter the script runtime.

      Returns Promise<ChannelHandle>

      The open channel's public id. Pairing secrets stay in trusted PowerKeys UI.

      Messages are encrypted in the host; the PowerKeys relay forwards opaque ciphertext and stamps the authenticated room member. A room can have many members: anyone who receives a shared code can join while its owner permits joins. Register Channel.OnMessage to receive messages. Treat every inbound message as untrusted input and allowlist exact sender.memberId values before a message can cause keyboard, file, network, or other privileged work. Sender metadata is relay-authenticated admission attribution, not a cryptographic signature from the sender. The Promise resolves after trusted admission and WebSocket establishment. Authorization or WebSocket failures reject it. Saved pairing codes are local to this installation, server, account, and script. Removing a member stops future relay admission, but cannot take a code or room secret already shared with that member back.

      const ch = await Channel.Open();
      Channel.OnMessage((m) => Console.Log(m.sender.memberId + ": " + m.data));
      await Channel.Send(ch.channelId, "hello");

      channels

    • Sends a message to the other members of an open room channel.

      Parameters

      • channelId: string

        The channel id returned by Channel.Open.

      • data: string

        The message to send. At most 8,192 UTF-8 bytes; longer messages are rejected.

      Returns Promise<void>

      Resolves after encryption hands the message to the socket writer; it does not confirm recipient processing and rejects if the room closes first.

      channels

    • Registers a handler for messages received on any open channel. The script stays alive as long as a handler is registered.

      Parameters

      • callback: EventCallback<
            [
                message: {
                    channelId: string;
                    messageId: string;
                    sender: { memberId: string; connectionId: string };
                    source: "channel";
                    sentAt: string;
                    data: string;
                },
            ],
        >

        Handler receiving each sender-attributed inbound message. Treat data as untrusted input.

      Returns void

      channels

    • Closes an open channel and tears down its connection.

      Parameters

      • channelId: string

        The channel id returned by Channel.Open.

      Returns void

      channels