Introduction
In this tutorial, we'll explore how to build and deploy an AI-powered productivity assistant similar to what OpenAI developer Thibault Sottiaux described with Astra. This assistant will help automate routine tasks and improve workflow efficiency. We'll create a Python-based system that integrates with popular productivity tools like Notion, Slack, and email, using AI to process and respond to user requests.
Prerequisites
- Python 3.8 or higher
- Basic understanding of APIs and webhooks
- Access to Notion, Slack, and email accounts with API access
- OpenAI API key
- Basic knowledge of Python libraries like requests, Flask, and datetime
Step-by-Step Instructions
1. Set Up Your Development Environment
First, create a virtual environment and install the required packages:
python -m venv productivity_assistant
source productivity_assistant/bin/activate # On Windows: productivity_assistant\Scripts\activate
pip install flask requests python-dotenv openai notion
This creates an isolated environment to prevent package conflicts and installs all necessary libraries for our assistant.
2. Create Environment Configuration
Create a .env file in your project root to store your API keys securely:
OPENAI_API_KEY=your_openai_api_key_here
NOTION_API_KEY=your_notion_api_key_here
SLACK_BOT_TOKEN=your_slack_bot_token_here
NOTION_DATABASE_ID=your_notion_database_id
Storing credentials in environment variables keeps them secure and prevents accidental exposure in version control.
3. Initialize the AI Assistant Class
Create a assistant.py file with the core AI assistant functionality:
import openai
import os
from dotenv import load_dotenv
load_dotenv()
class ProductivityAssistant:
def __init__(self):
openai.api_key = os.getenv('OPENAI_API_KEY')
self.system_prompt = """
You are a productivity assistant that helps with task management, scheduling, and information retrieval.
You can process natural language requests and respond with appropriate actions or information.
"""
def process_request(self, user_input):
response = openai.ChatCompletion.create(
model="gpt-4",
messages=[
{"role": "system", "content": self.system_prompt},
{"role": "user", "content": user_input}
]
)
return response.choices[0].message.content
This class initializes the OpenAI API and sets up a system prompt that defines the assistant's role in productivity tasks.
4. Integrate with Notion API
Add Notion integration to the assistant:
import requests
NOTION_API_URL = "https://api.notion.com/v1"
NOTION_DATABASE_ID = os.getenv('NOTION_DATABASE_ID')
NOTION_API_KEY = os.getenv('NOTION_API_KEY')
headers = {
"Authorization": f"Bearer {NOTION_API_KEY}",
"Content-Type": "application/json",
"Notion-Version": "2022-06-28"
}
def create_notion_task(task_name, description=""):
payload = {
"parent": {"database_id": NOTION_DATABASE_ID},
"properties": {
"Name": {"title": [{"text": {"content": task_name}}]},
"Status": {"select": {"name": "To Do"}},
"Description": {"rich_text": [{"text": {"content": description}}]}
}
}
response = requests.post(f"{NOTION_API_URL}/pages", headers=headers, json=payload)
return response.json()
This function creates new tasks in your Notion database, which is essential for task automation.
5. Implement Slack Integration
Create a function to send messages to Slack:
import slack
slack_client = slack.WebClient(token=os.getenv('SLACK_BOT_TOKEN'))
def send_slack_message(channel, message):
try:
response = slack_client.chat_postMessage(
channel=channel,
text=message
)
return response
except Exception as e:
print(f"Error sending Slack message: {e}")
return None
Slack integration allows the assistant to communicate directly with team members, making it a true productivity tool.
6. Build the Main Application
Create a Flask app to handle incoming requests:
from flask import Flask, request, jsonify
app = Flask(__name__)
assistant = ProductivityAssistant()
@app.route('/assistant', methods=['POST'])
def handle_assistant_request():
data = request.json
user_input = data.get('input', '')
# Process with AI
ai_response = assistant.process_request(user_input)
# Handle specific tasks
if 'create task' in user_input.lower():
task_name = user_input.split('create task ')[1].strip()
result = create_notion_task(task_name)
ai_response += f"\nCreated task in Notion: {result.get('id', 'Unknown')}"
return jsonify({"response": ai_response})
if __name__ == '__main__':
app.run(debug=True)
This endpoint receives user requests, processes them with AI, and performs actions like creating Notion tasks.
7. Test Your Assistant
Run your Flask app and test with a simple curl command:
curl -X POST http://localhost:5000/assistant \
-H "Content-Type: application/json" \
-d '{"input": "Create a task to review the quarterly report in Notion"}'
Ensure your assistant correctly processes the request and creates the task in Notion.
Summary
This tutorial demonstrated how to build an AI productivity assistant that can automate routine tasks and integrate with popular productivity tools. By combining OpenAI's language models with APIs from Notion, Slack, and email, we created a system that can process natural language requests and perform actions automatically. The assistant can be extended with additional integrations and more complex AI processing to further boost productivity, similar to what OpenAI's Astra reportedly achieved.
Key concepts covered include API integration, natural language processing with OpenAI, task automation, and webhook handling. This foundation can be expanded to include more sophisticated features like scheduling, data analysis, and team collaboration tools.

