Compose and send messages to single or multiple recipients in Toloka.
Connect the Toloka-Kit library to your script.
import toloka.client as toloka
Replace the sample API key with your own one.
toloka_client = toloka.TolokaClient('PlaceYourRealApiKey_Here', 'PRODUCTION');
Now compose a message for Tolokers. For this, you need the following information:
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)
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!
import toloka.client as tolokatoloka_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])
Last updated: February 7, 2023