Send messages

Compose and send messages to single or multiple recipients in Toloka.

Steps to follow

1. Import Toloka-Kit

Connect the Toloka-Kit library to your script.

import toloka.client as toloka

2. Instantiate TolokaClient

Replace the sample API key with your own one.

toloka_client = toloka.
TolokaClient
('PlaceYourRealApiKey_Here', 'PRODUCTION');

3. Send message to Tolokers

Now compose a message for Tolokers. For this, you need the following information:

  • the message text and topic
  • whether the recipients can reply to the message or not

You also need to select the message recipients. If you choose to send the message to all the Tolokers, you will simply need to set the recipients_select_type value to 'DIRECT'. Otherwise, you will need to specify the IDs of the Tolokers whom you want to receive the message.

message_thread = toloka_client.
compose_message_thread
(

recipients_select_type='DIRECT',

recipients_ids=['1ad097faba0eff85a04fe30bc04d53db'],
topic={'EN': 'Thank you!'},
text={'EN': 'Amazing job! We have just trained our first model.'},
answerable=False
)

4. Display sent message info

The compose_message_thread() request will return the MessageThread class object. You can use its attributes to print the information you need.

print(message_thread.id, message_thread.topic.get('EN') or list(message_thread.topic.values())[0])

You should get an output with the message ID and topic which looks like this.

63c15866757a4a1adad1d632 Thank you!

Complete code: Send messages

import toloka.client as toloka
toloka_client = toloka.TolokaClient('PlaceYourRealApiKey_Here', 'PRODUCTION')
message_thread = toloka_client.compose_message_thread(
recipients_select_type='DIRECT',
recipients_ids=['1ad097faba0eff85a04fe30bc04d53db'],
topic={'EN': 'Thank you!'},
text={'EN': 'Amazing job! We have just trained our first model.'},
answerable=True
)
print(message_thread.id, message_thread.topic.get('EN') or list(message_thread.topic.values())[0])
List of classes and methods used in this recipe

See also

Last updated: February 7, 2023

Toloka-Kit
OverviewGetting API keyQuick start
Recipes
Reference
toloka.client
toloka.async_client
toloka.autoquality [autoquality]
toloka.metrics
toloka.streaming