Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ The compose file reads three variables from the environment. All of them have a
| Variable | Default | Description |
|-----|-----|-------------|
| `STATUS_GO_COMMIT` | `develop` | The [`status-im/status-go`](https://github.com/status-im/status-go/) git ref (commit SHA, branch or tag) to build from. |
| `STATUS_GO_PLATFORM` | `linux/amd64` | The platform the image is built for. |
| `PLATFORM` | `linux/amd64` | The platform the image is built for. |

```
STATUS_GO_COMMIT=2bee8b6a38cdc8f92d74e2dbb8c4e77fbbeea149 PLATFORM=linux/amd64 docker compose -f status_sdk/docker-compose.yaml up -d
Expand Down
116 changes: 102 additions & 14 deletions docs/account.md
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,69 @@ account.send_image(
)
```

#### `send_bridged_message(chat_id, message, name=None, username=None, user_id=None, message_id=None, reply_to_message_id=None, image_url=None)`

Relay a message that came from **another messaging platform** - Discord, Telegram, Slack, IRC - into a Status chat. Status App renders it as a **bridged message** - the original author's name and avatar are shown, with the platform it came from, rather than the message appearing to come from the bot account itself.

| Name | Type | Required | Description |
|-----|-----|-----|-------------|
| `chat_id` | `str` | Yes | Identifier of the chat where the message will be sent. All available chat IDs come from the [`chats`](./account.md#chats) property. |
| `message` | `str` | Yes | The text of the original message. |
| `name` | `str` | No | The platform the message came from, shown as the bridge label in Status App - for example `Discord`. Defaults to `Unknown`. |
| `username` | `str` | No | The author's username **on the other platform**, shown as the sender. Defaults to `Anon`. |
| `user_id` | `str` | No | The author's id on the other platform. Status uses it to tell one bridged author from another, so **pass the real id** - see the note below. |
| `message_id` | `str` | No | The original message's id on the other platform. Pass it if you want later messages to be able to reply to this one. |
| `reply_to_message_id` | `str` | No | The **other platform's** id of the message being replied to - *not* a Status message id. Unlike in [`send_message`](./account.md#send_messagechat_id-message-reply_to_message_idnone) and [`send_image`](./account.md#send_imagechat_id-file_path-messagenone-reply_to_message_idnone). It threads correctly only when the message it points at was itself relayed with that same value as its `message_id`. Passing a Status id will not thread. |
| `image_url` | `str` | No | URL of the author's avatar on the other platform. Defaults to no avatar. |

Returns `str` - the `id` of the message **in Status App**, which is a different value from the `message_id` you passed in. It can be used with [`delete_message`](./account.md#delete_messageid) like any other sent message.

```python
from status_sdk import Account

account = Account()
params = {
"name": "status-app-bot",
"password": "SNTPUMP"
}
account.login(**params)

chat = account.chats[0]

status_id = account.send_bridged_message(
chat_id=chat["id"],
message="Has anyone tried the new build?",
name="Discord",
username="thedatabro",
user_id="356712449896382465",
message_id="1180937465829183498",
image_url="https://cdn.discordapp.com/avatars/356712449896382465/a1b2c3.png"
)
print(f"Relayed into Status as {status_id}")
```

Threading a reply that happened on the other platform:

```python
account.send_bridged_message(
chat_id=chat["id"],
message="Yes, works on my machine",
name="Discord",
username="alex",
user_id="481920374651829301",
message_id="1180937812345678901",
# The Discord id of the message being replied to, relayed earlier
reply_to_message_id="1180937465829183498"
)
```

**Note**: `user_id` and `message_id` both fall back to a **freshly generated UUID** when omitted.

1. Without `user_id`, every relayed message looks like it came from a different author even when the same person sent them all;
2. without `message_id`, nothing can ever reply to that message, because the id it would need to reference is discarded. A real bridge should pass both.

The same method is available on [`GroupChat`](./group-chat.md#send_bridged_messagemessage-namenone-usernamenone-user_idnone-message_idnone-reply_to_message_idnone-image_urlnone) and on a community [`Channel`](./community.md#send_bridged_messagemessage-namenone-usernamenone-user_idnone-message_idnone-reply_to_message_idnone-image_urlnone) without the `chat_id` argument, since those already know their own chat.

#### `send_emoji_reaction(message_id, emoji_shortname, chat_id=None)`

React to a message with an emoji, the same as reacting to a message in Status App. The reaction is a **toggle** - calling the method again with the same emoji on the same message removes it, so the same call both sets and unsets the reaction.
Expand Down Expand Up @@ -661,12 +724,13 @@ for msg in account.listen_messages():

#### `listen_contact_requests()`

Listen for contact requests **in real time**. Both **incoming** contact requests sent to the account and contact requests sent by the account that were **accepted** by the other user are yielded. Every yielded event carries a `request_type` key that tells the two apart:
Listen for contact requests **in real time**. . Every yielded event carries a `request_type` key that tells them apart:

| `request_type` | Meaning |
|-----|-----|
| `incoming` | Another user sent a contact request to the account. Approve it with [`add_contact`](./account.md#add_contactpublic_key-display_namenone). |
| `incoming` | Another user sent a contact request to the account. Approve it with [`add_contact`](./account.md#add_contactpublic_key-display_namenone). Use `id` and `public_key` properties from `ContactRequest` |
| `accepted` | Another user accepted a contact request that the account had sent. The contact is now mutual. |
| `removed` | When a user has removed the account from their contacts. |

```python
from status_sdk import Account
Expand Down Expand Up @@ -695,10 +759,12 @@ params = {
account.login(**params)

for request in account.listen_contact_requests():
if request["request_type"] == "incoming":
if request.incoming:
print("New contact request received")
elif request["request_type"] == "accepted":
elif request.accepted:
print("Contact request was accepted")
elif request.removed:
print(f"{request.public_key} has removed you")
```

#### `listen_message_mentions()`
Expand All @@ -719,20 +785,14 @@ for mention in account.listen_message_mentions():
print(mention)
```

#### `add_contact(public_key, display_name=None)`

Send a contact request or approve an existing contact request. The mode depends on how the contact shows up in [`contacts`](./account.md#contacts). Best practice would be to look at the the following [`contacts`](./account.md#contacts) keys:
#### `add_contact(public_key, request_id=None, display_name=None)`

- `has_added_us` - `bool` value to check if the other user has added the account as a friend
- `added` - `bool` value to check if the account has added the other user as a friend
- `mutual` - `bool` value to check if the account and other user are in contacts
- `contact_state` - `str` value to see the account's current state
- `external_contact_state` - `str` value to see the other user's state as it is in your node
Send a contact request or approve an existing contact request.

Modes:

- **Approve mode** - `has_added_us` is `True` and `added` is `False`
- **Add mode** - `has_added_us` is `False`
- **Approve mode** - use `public_key` and `request_id`
- **Add mode** - `public_key` and `display_name`. Display name can be omitted if the account shows up in [`contacts`](./account.md#contacts)

The contact can be identified in three different ways, so you can pass whichever value you have at hand - the public key, the chat key as shown in Status App, or the profile link a user shares with you:

Expand All @@ -747,6 +807,7 @@ When an account URL is passed, the public key is resolved from it automatically
| Name | Type | Required | Description |
|-----|-----|-----|-------------|
| `public_key` | `str` | Yes | The contact's Status **public key** (`0x...`), **chat key** (`zQ...`) or **account URL** (`https://...`). |
| `request_id` | `str` | No | The `id` of an incoming contact request, from the `ContactRequest` yielded by [`listen_contact_requests`](./account.md#listen_contact_requests). Passing it switches the method into **approve mode** - the pending request is accepted instead of a new one being sent, and `display_name` is not used at all. Omit it to send a **new** contact request. |
| `display_name` | `str` | Yes / No | Display name for the contact. If the contact already exists in [`contacts`](./account.md#contacts), the `display_name` parameter is optional and the existing name will be reused. If the contact has **never interacted with the bot before**, `display_name` must be provided so the contact can be created locally. |

Returns the current `Account` instance, allowing method chaining.
Expand Down Expand Up @@ -1908,6 +1969,33 @@ for chat in account.chats:
print(f"{chat['type']}\t{chat['name']}\t{chat['id']}")
```

#### `message_length`

The maximum number of characters a single message may contain, as enforced by Status App.

Returns `int`.

```python
from status_sdk import Account

account = Account()
params = {
"name": "status-app-bot",
"password": "SNTPUMP"
}
account.login(**params)

print(account.message_length)

# This is under the assumption you already have a contact / joined a community
chat = account.chats[0]
report = "A very long report..."

# Split a long text into messages the app accepts
for index in range(0, len(report), account.message_length):
account.send_message(chat["id"], report[index:index + account.message_length])
```

### Wallet

#### `chains`
Expand Down
Loading
Loading