3. Develop your bot (5 mins)
This step creates a bot file, then run it with one CLI command.
Prerequisite: QueryStar SDK, and a QueryStar token saved as QUERYSTAR_TOKEN
as an environment variable.
Step 1: Create a Python file​
Open your favorite code editor, paste the follow script in a file, and name the file bot.py
.
# bot.py
import querystar as qs
# Triggered by new messages sent to channel #introduction
qs.triggers.slack.new_message(channel_id='C05Q36Z6GGM')
# Send a message to channel #introduction saying 'Hello!'
qs.actions.slack.add_message(channel_id='C05Q36Z6GGM',
text='Hello!')
You can find your channel id here:
Step 2: Add Querystar app
to the channel​
On the channel config page, under
Integrations
tab, clickAdd apps
button.Then find
QueryStar
in the app list, click theAdd
button.
Step 2 can be skipped if QueryStar has been already added to the channel of interest. You can verify it here:
Step 3: Run the bot​
In your terminal, make sure you are in the folder where `bot.py`` is, then run this command:
$ querystar run bot.py
Now switch to Slack to test. Your bot should respond to any new message now:
:::And, you will see this message in the terminal:
Running bot.py
Running:: triggers.slack.new_message
Finished:: triggers.slack.new_message
Running:: actions.slack.add_message
Finished:: actions.slack.add_message
It means a full cycle of Trigger -> Action
has been completed.
🥳 Congratulations to you for making the bot .
More demos can be found in page Tutorials
.