semaphore.Bot

class semaphore.Bot(username: str, profile_name: str | None = None, profile_picture: str | None = None, profile_emoji: str | None = None, profile_about: str | None = None, group_auto_accept: bool = True, logging_level: int = 20, socket_path: str | None = None, raise_errors: bool = False)[source]

Bases: object

This object represents a simple (rule-based) Signal Private Messenger bot.

async accept_invitation(group_id: str) None[source]

Accept a v2 group invitation.

Parameters:

group_id – Group id to accept invitation from.

async add_members(group_id: str, members: list) GroupV2[source]

Add members to a group.

Parameters:
  • group_id – Group id to add the members to

  • members – List of members uuids to be added

Returns:

Returns the updated GroupV2 object

async create_group(title: str, members: list) GroupV2[source]

Create a Signal group.

Parameters:
  • title – title for the new group

  • members – List of members uuids to be added to the new group

Returns:

Returns the created GroupV2 object

async get_group(group_id: str) GroupV2[source]

Get details of a group.

Parameters:

group_id – Group id to get details for

Returns:

Returns a GroupV2 object

handler(regex: Pattern) Callable[source]

Decorator to register handlers.

async leave_group(group_id: str) None[source]

Leave a Signal group.

Parameters:

group_id – Identifier of the group to leave

async list_groups() List[GroupV2][source]

List of v2 groups for an account.

Returns:

Returns a list of v2 group objects

async preview_group(url: str) GroupV2[source]

Preview information about a group without joining.

Parameters:

url – Group invite link to preview information for

Returns:

Returns a GroupV2 object

register_handler(regex: str | Pattern, func: Callable) None[source]

Register a chat handler with a regex.

async remove_members(group_id: str, members: list) GroupV2[source]

Remove members from a group.

Parameters:
  • group_id – Group id to remove the members from

  • members – List of members uuids to be removed

Returns:

Returns the updated GroupV2 object

async send_message(receiver: str, body: str, attachments: List[Attachment] | None = None, link_previews: List[LinkPreview] | None = None) bool[source]

Send a message.

Parameters:
  • receiver – The receiver of the message (uuid or number).

  • body – The body of the message.

  • attachments – Optional attachments to the message.

  • link_previews – Optional link previews for the message.

Returns:

Returns whether sending is successful

Return type:

bool

async set_expiration(receiver: str, time: int) None[source]

Set the message expiration timer for a chat.

Parameters:
  • receiver – The receiver for which to set the expiration time.

  • time – Time must be specified in seconds, set to 0 to disable timer.

async set_profile(profile_name: str, profile_avatar: str | None = None, profile_emoji: str | None = None, profile_about: str | None = None) None[source]

Set Signal profile.

Parameters:
  • profile_name – New profile name, empty string for no profile name.

  • profile_avatar – Path to profile avatar file.

  • profile_emoji – Emoji character visible in profile.

  • profile_about – Description text visible in profile.

async start() None[source]

Start the bot event loop.

async update_group_access_control(group_id: str, access_control: str, role: str) GroupV2[source]

Change a group’s access control.

Parameters:
  • group_id – Identifier of the group to update avatar for

  • access_control – Name of the access control, options are: attributes|members|link

  • role – Set the role of an access control: for attributes otions are: UNSATISFIABLE|ADMINISTRATOR|ANY for members otions are: MEMBER|ADMINISTRATOR for link options are: MEMBER|ADMINISTRATOR

Returns:

Returns the updated GroupV2 object

async update_group_avatar(group_id: str, avatar: str) GroupV2[source]

Change a group’s avatar.

Parameters:
  • group_id – Identifier of the group to update avatar for

  • avatar – Path to group avatar file

Returns:

Returns the updated GroupV2 object

async update_group_role(group_id: str, member_id: str, role: str) GroupV2[source]

Update role of a member in the group.

Parameters:
  • group_id – Identifier of the group to update member role for

  • member_id – Identifier of the member

  • role – Updated role of the member

Returns:

Returns the updated GroupV2 object

async update_group_timer(group_id: str, timer: str) GroupV2[source]

Update a group’s timer.

Parameters:
  • group_id – Identifier of the group to change timer of

  • timer – Expiration must be specified in seconds, 0 to disable timer

Returns:

Returns the updated GroupV2 object

async update_group_title(group_id: str, title: str) GroupV2[source]

Update a group’s title.

Parameters:
  • group_id – Identifier of the group to update the title for

  • title – New title

Returns:

Returns the updated GroupV2 object