Skip to main content

Phound SDK

Project description

Installing

pip install phound

Usage

Create and fill in .env file within your project's directory with:

SBC=wss://ow-sbc.phound.app/ucp
UID=<uid>
TOKEN=<token>

Simple python chatbot could look like:

import os
import time

from phound import Phound
from phound.handlers import BaseChatHandler


class ChatHandler(BaseChatHandler):
    def on_message(self, message):
        print(f"Got new message: {message}")
        self.show_typing()
        time.sleep(1)
        chat_history = self.get_history(depth=10)
        reply_items = [f"Initial message: {message.text}",
                       f"response: {message.text[::-1]}",
                       f"also got chat history with last {len(chat_history)} messages"]
        self.send_message(os.linesep.join(reply_items))


if __name__ == "__main__":
    with Phound() as phound:
        phound.register_chat_handler(ChatHandler)
        phound.start_listen_events()

API Reference

Phound:

The Phound interface provides the following methods:

  • register_chat_handler(self, handler: BaseChatHandler, chat_types: Tuple[str, ...] = ("private",)) - Registers specified chat handler, chat_types accepts tuple of chat types to handle, valid values are "private" and "group"
  • start_listen_events() - Starts listen events

BaseChatHandler:

Each instance of BaseChatHandler provides the following interface:

Attributes:

  • persona_uid: str - The unique ID of the persona listening to the chat.
  • chat_type: str - Either "private" or "group".

Methods:

  • on_message(self, message: Message) - Called when a new message is received in the chat.
  • show_typing(self, timeout: int = 60) - Displays a typing indicator in the chat. The indicator is shown for the specified timeout or until the next message is sent by the handler.
  • send_message(self, text: str) - Sends a message with the specified text to the chat.
  • get_history(self, depth: int = 10, start_message_id: str = "0") - Retrieves the chat history as a list of Message objects. The depth parameter determines the number of messages to retrieve, and start_message_id can be used to obtain history starting from a specific message ID. Using "0" as the start_message_id starts from the last message.

Message:

The Message interface provides the following attributes:

  • id: str - The ID of the message.
  • text: str - The text content of the message.
  • from_uid: str - The unique ID of the persona from which the message originated.
  • tagged: bool - Indicates whether the persona listening to the chat was tagged in the message.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

phound-0.1.0-py3-none-manylinux_2_35_x86_64.whl (3.3 MB view details)

Uploaded Python 3manylinux: glibc 2.35+ x86-64

phound-0.1.0-py3-none-macosx_14_0_arm64.whl (1.2 MB view details)

Uploaded Python 3macOS 14.0+ ARM64

File details

Details for the file phound-0.1.0-py3-none-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for phound-0.1.0-py3-none-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 4e98666609cc81a81314fb54544db4edbd246dffcca15f47a1638cff9c61e789
MD5 833fb38d5cde6030b05d4956eadc63f4
BLAKE2b-256 9b44eca65ea4d397a24145232e10877b6d337fbae0d307d09d2b9a09514a3198

See more details on using hashes here.

File details

Details for the file phound-0.1.0-py3-none-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for phound-0.1.0-py3-none-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 f698dd830750001fd515206f0204cce3ee640e23f40b7b6069faf6abcb079c7d
MD5 f659e63361a347af00e4ed88c5523de1
BLAKE2b-256 1f0e08d2244b0988582de7a5d651e05f9596caf231601d0e165bf0da0698f707

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page