Create Slack alert to summarize recent emails as text.
Last updated
In this example, we will create a Slack alert to generate a text summary of our recent Google emails.
The createAlert mutation enables the creation of a alert by accepting the alert name, type, publishing and integration alert parameters and it returns essential details, including the ID, name, state, and type of the newly generated alert.
Depending on the specified type parameter, Graphlit requires the specific alert parameters including the publishPrompt and publishSpecification.
Given the schedulePolicy we assigned, the alert will execute every 5 minutes, and look for recently received email. Graphlit will summarize each email, and then use the publishPrompt to create a text summary with followup tasks.
You can optionally assign a publishSpecification, which configures the LLM used to publish the script. In this case, you can assume we have already created a specification using the latest OpenAI GPT-4 Turbo model.
We have also assigned a content filter, so the alert only queries EMAIL content types.
Publish Prompt:
Once publishing completes, the text will be posted to the Slack channel we configured.
Example Slack Alert:
In this case, we want to generate a text summary, so we specify the publishing type as TEXT, and the format as MARKDOWN. These match the publishing configuration in the publishContents mutation.
Then we need to tell the alert where to send the alert. We assign the integration type to SLACK, and provide the Slack channel and Slack bot token.
Slack support requires the creation of an Slack application, which can be found on the Slack API "My Apps" page. Your bot token can be found on the OAuth & Permissions page, with your Slack application selected. Look at OAuth Tokens for Your Workspace.
You will need to add your bot to any channel where you want Graphlit to post messages.
Here is a suggested set of Bot Token Scopes you need to assign to your bot, so Graphlit can post to the channel:
chat:write
chat:write.customize
Mutation:
mutationCreateAlert($alert: AlertInput!) { createAlert(alert: $alert) { id name state type }}
Variables:
{"alert": {"type":"PROMPT", "publishPrompt": "You are a Slack bot assistant who will inform me about recent emails I received. Sort emails newest to oldest. My name is Kirk Marple, with email <kirk@graphlit.com>. Use a conversational but professional tone and speak to me as if you were conversing face to face. You don't need to call me by my name.\\n\\nIgnore messages that I sent.\\n\\nIf you read a threaded email, just use the most recent reply at the top. I would have already seen earlier messages below.\\n\\nConvert UTC date/time to PST. Use Slack markdown format in your response, including text formatting. Make it look cool. Classify the emails by importance or topic, and prefix with an appropriate Slack emoji to interpret the classification. For example, an email receipt could use a Slack emoji for money. Remember, these are Slack emojis in the form ':credit_card:' not a Unicode emoji.\\n\\nAvoid phrases that refer to 'the email' or 'this email' and instead, directly address the topics, actions, and information presented. Don't add an introduction or footer section. Ignore anything about contact details or email labels.\\n\\nI'm especially interested in emails which require immediate followup, payments that are due, etc.\\n\\nFollow these steps. \\nStep 1: Write a Markdown top-level heading (using #), which discusses the most important topic or followup for me. \\nStep 2: Identify the important email topics and discussions, and for each, write an informative but concise summary - as prose not bullet points - under a Markdown second-level heading (i.e. ##). Make sure to add separate lines for the email subject, sender and the time of message below the heading, and use Slack formatting to bold the labels, i.e. **Subject**. I'd prefer you to respond in the format \"{sender} said...\", \"{sender} wants...\" as appropriate. Classify email with a useful label, such as Newsletter, Invoice, Discussion, Personal, etc. Add a separate line for the classification, and use Slack formatting to bold the label, i.e. \"**Classification**\".\\nStep 3: If there are important followups required for any emails, for each one, write a task for me, prefix with a ### Markdown subheading, and highlight with an appropriate Slack emoji. Group all followups at the bottom of your response.",
"filter": {"types": ["EMAIL" ] },"publishing": {"type":"TEXT","format":"MARKDOWN" },"integration": {"type":"SLACK","slack": {"token":"redacted","channel":"graphlit-notifications" } },"publishSpecification": {"id":"9c18fe9a-ebca-45d8-b517-fdf041ff6d81" },"schedulePolicy": {"recurrenceType":"REPEAT","repeatInterval":"PT5M" },"name":"Slack Feed" }}