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:

PERSONAS=<uid1> <uid2> ...
TOKEN=<token>

where uid1 uid2 etc. represent personas to listen. If no one specified(or omitted), all personas within an account will be listened to.

Please refer to support@phound.app to get a 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_start(self):
        self.chat_history = self.get_history(depth=5)

    def on_message(self, message):
        print(f"Got new message: {message}")
        self.chat_history.append(message)
        self.show_typing()
        time.sleep(1)
        reply_items = [f"Initial message: {message.text}",
                       f"Response: {message.text[::-1]}",
                       f"Also has chat history with last {len(self.chat_history)} messages"]
        reply = self.send_message(os.linesep.join(reply_items))
        self.chat_history.append(reply)


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

API Reference

Phound

Methods:

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

BaseChatHandler

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

Event handlers:

  • on_start(self) - Called once when the chat handler is started.
  • on_message(self, message) - Called when a new message is received in the chat.
    • message: Message - The message object.

Methods:

Same as for Chat object, please refer to the documentation bellow.

BaseCallHandler

  • persona_uid: str - The unique ID of the persona listening to the call.
  • chat: Chat - The chat object associated with the call.

Event handlers:

  • on_start(self) - Called once when the call handler is started.
  • on_incoming_call(self, call) - Called when an incoming call is received.
    • call: Call - The call object.
  • on_call_ready(self) - Called when a call is ready.
  • on_playback_status(self, status) - Called when the playback status changes.
    • status: PlaybackStatus - Enum, one of PlaybackStatus.IN_PROGRESS or PlaybackStatus.COMPLETE.
  • on_audio_chunk_recorded(self, audio_chunk) - Called when an audio chunk is recorded.
    • audio_chunk: AudioChunk - The audio chunk object.
  • on_hangup(self) - Called when the call is hung up.
  • on_attendee_join(self, attendee) - Called when an attendee joins the call.
    • attendee: CallAttendee - The CallAttendee object.
  • on_attendee_drop(self, attendee) - Called when an attendee drops the call.
    • attendee: CallAttendee - The CallAttendee object.

Methods:

  • answer(self) - Answers the call.
  • reject(self) - Rejects the call.
  • hangup(self) - Hangs up the call.
  • play(self, file_path) - Plays the specified audio file in the call.
    • file_path: str - The path to the audio file.
  • record(self, file_path, min_chunk_len=0, max_chunk_len=0, chunk_overlap=0) - Records the call and saves it to the specified file.
    • file_path: str - The path to the audio file.
    • min_chunk_len: int - The minimum length of the audio chunk in seconds.
    • max_chunk_len: int - The maximum length of the audio chunk in seconds.
    • chunk_overlap: int - The overlap of the audio chunks in seconds.
  • get_active_attendees(self) - Returns a list of active attendees (CallAttendee) in the call.
  • get_all_attendees(self) - Returns a list of all attendees (CallAttendee) in the call.

Chat

  • persona_uid: str - The unique ID of the persona listening to the chat.
  • chat_id: str - The ID of the chat.

Methods:

  • show_typing(self, timeout=60, chat_id="", persona_uid="", phone_number="") - Displays a typing indicator in the chat. The indicator is shown for the specified timeout or until the next message is sent.
    • timeout: int - The timeout in seconds.
    • chat_id: str - The ID of the chat to show the typing indicator in. If not specified, the typing indicator is shown in the handled chat.
    • persona_uid: str - The unique ID of the persona to show the typing indicator in chat with. If not specified, the typing indicator is shown in the handled chat.
    • phone_number: str - The phone number to show the typing indicator in chat with. If not specified, the typing indicator is shown in the handled chat.
  • send_message(self, text, text_format=MessageTextFormat.PLAIN, attachments=None, app_meta=None, chat_id="", persona_uid="", phone_number="") - Sends a message with the specified text to the chat.
    • text: str - The text content of the message. Please see also the "Text helpers" section bellow.
    • text_format: MessageTextFormat | None - The text format of the message. One of MessageTextFormat.HTML, MessageTextFormat.PLAIN or MessageTextFormat.GPTMARKDOWN.
    • attachments: List[str] | None - A list of attachment as path to be added to the message.
    • app_meta: Dict[str, Any] | None - A dictionary of additional metadata to be added to the message.
    • chat_id: str - The ID of the chat to send the message to. If not specified, the message is sent to the handled chat.
    • persona_uid: str - The unique ID of the persona to send the message to. If not specified, the message is sent to the handled chat.
    • phone_number: str - The phone number to send the message to. If not specified, the message is sent to the handled chat.
  • get_history(self, depth=10, start_message_id="0", chat_id="", persona_uid="", phone_number="") - Retrieves the chat history as a list of Message objects.
    • depth: int - The number of messages to retrieve.
    • start_message_id: str - The ID of the message to start from. Use "0"(default) to start from the last message.
    • chat_id: str - The ID of the chat to retrieve the history from. If not specified, the history is retrieved from the handled chat.
    • persona_uid: str - The unique ID of the persona to retrieve the history from chat with. If not specified, the history is retrieved from the handled chat.
    • phone_number: str - The phone number to retrieve the history from chat with. If not specified, the history is retrieved from the handled chat.

Call

  • id: str - The ID of the call.
  • persona_uid: str - The unique ID of the persona who is listening to the call.
  • from_persona_uid: str - The unique ID of the persona who is calling.
  • from_name: str - The name of the persona who is calling.

CallAttendee

  • id: str - The ID of the attendee.
  • number: str - The phone number of the attendee.
  • name: str - The name of the attendee.
  • persona_uid: str - The unique persona ID of the attendee.

AudioChunk

  • audio_file_path: str - The path to the audio file.
  • asn_file_path: str | None - The path to the ASN file.
  • duration: float - The duration of the audio file in seconds.
  • last_chunk: bool - Indicates whether the audio chunk is the last in the recording.
  • full_audio_file_path: str | None - The path to the full audio file, if available.
  • full_duration: float | None - The duration of the full audio file in seconds, if available.

Message

  • 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.
  • from_name: str - The name of the persona from which the message originated.
  • tagged: bool - Indicates whether the persona listening to the chat was tagged in the message.
  • attachments: List[MessageAttachment] - A list of MessageAttachment objects.

MessageAttachment

  • name: str - The name of the attachment.
  • size: int - The size of the attachment.
  • url: str - The URL of the attachment.

Text helpers

Text helpers are the set of functions that are used to help to format the text of the message.

  • mention(persona_uid, label="")

    • persona_uid: str - The unique ID of the persona to mention.
    • label: str - The label of the persona to mention. If not specified, the label is the same as the persona_uid.
  • bold(text)

    • text: str - The text to bold.
  • italic(text)

    • text: str - The text to italicize.
  • underline(text)

    • text: str - The text to underline.

Example

from phound.chats.text_helpers import bold, italic, underline, mention

class ChatHandler(BaseChatHandler):
    ...
    text = (f"It's possible to use pure html tags to make text <b>bold</b>, or do it with {bold('helper')}\n"
            f"same for <i>italic</i> and <u>underline</u> ({italic('italic')}, {underline('underline')})\n"
            f"To mention someone use {mention('<uid>', 'name')}")
    self.send_message(text)

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.4-py3-none-win_amd64.whl (1.3 MB view details)

Uploaded Python 3Windows x86-64

phound-0.1.4-py3-none-manylinux_2_35_x86_64.whl (3.5 MB view details)

Uploaded Python 3manylinux: glibc 2.35+ x86-64

phound-0.1.4-py3-none-macosx_14_0_arm64.whl (1.3 MB view details)

Uploaded Python 3macOS 14.0+ ARM64

File details

Details for the file phound-0.1.4-py3-none-win_amd64.whl.

File metadata

  • Download URL: phound-0.1.4-py3-none-win_amd64.whl
  • Upload date:
  • Size: 1.3 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.8.3

File hashes

Hashes for phound-0.1.4-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 cd900b5c787bd42f91fa1d2f6a19eda38cd665cbb42c333e4139e2d5b43bf1c6
MD5 20c283fb326c1d5da52699090b8a6653
BLAKE2b-256 7405b45795b286fcfdf3fc8b910e603b7dd478a19f35d56bfd1534ca77eb9a76

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phound-0.1.4-py3-none-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 d60b23f7d98d918e019ca13e75ee8e7bbd564b9b6343de377782f2b4a9be5d13
MD5 a48ef75e0db9488153e240fc6dedf2d1
BLAKE2b-256 03b350bf5d0512461d4bd12b32cd60b666ac66d2cafdce6cdc80333aa63aab6d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phound-0.1.4-py3-none-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 80894efa719200ff48e9d4089b5394646d3235db1909b17de3735277908ba3cc
MD5 52a8d8b8ad4848a146801c08b1fea195
BLAKE2b-256 e157bf880fd380a1c83f16b69eb00bb802cf27fb57a60c8deee1880e0f008e31

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