Skip to content

Create Bots on Check

Daniela Feitosa edited this page Nov 24, 2021 · 4 revisions

Developing a bot that connects to Check API makes easier to automate tasks that should be executed when some action occurs and perform changes to your workspace data. Bots can interact with Check API by subscribing to events and modifying the data using GraphQL queries.

This article describes how to create a bot on CheckAPI to notify external bots. Read about Creating bots for Check API to see what is needed to create an external bot to interact with Check API.

The bot created listen to the event publish_report and returns information about the report and the item:

# Create the API Key
a = ApiKey.create
a.expire_at = a.expire_at.since(100.years)
a.save

# Team where the Bot will be added
team = Team.find <id>

# Create the Bot and configure it
bot_user = BotUser.new
bot_user.name = "Report Bot"
bot_user.api_key = a
bot_user.set_request_url = "<webhook>"
bot_user.team_author_id = team.id
bot_user.set_events = [{ event: 'publish_report', graphql: "data, project_media { title, dbid, status, report_status, media { quote, url }}" }]

# If needed, set the headers to include when sending the notification
bot_user.set_headers = { 'X-Header' => 'ABCDEFG' }

bot_user.save

# A TeamBotInstallation will be created automatically adding the bot to the team with the role `contributor`
# Change the Bot's role to `editor` or `admin` of the Team to give more permissions to manage your workspace
team_bot_installation = TeamBotInstallation.find_by team: team, user: bot_user
team_bot_installation.role = 'editor'  # or 'admin'
team_bot_installation.status = 'member'
team_bot_installation.save