Releases: nylas/nylas-python
v5.14.0
This release of the Nylas Python SDK brings a couple of new features.
Release Notes
Added
- Added support for verifying webhook signatures (#257)
- Added optional parameter for token-info endpoint (#256)
Verifying webhook signatures
from flask import Flask, request, jsonify
from nylas import APIClient, Webhook
import os
import json
app = Flask(__name__)
port = 9000
NYLAS_CLIENT_SECRET = os.environ.get("NYLAS_CLIENT_SECRET")
@app.route("/", methods=["POST"])
def webhook_callback():
signature = request.headers.get("X-Nylas-Signature")
request_data = json.dumps(request.get_json())
if not Webhook.verify_webhook_signature(signature, request_data, NYLAS_CLIENT_SECRET):
return jsonify({"error": "Invalid signature"}), 403
body = request.json
print("Webhook event received: ", json.dumps(body))
return jsonify({"success": True}), 200
if __name__ == "__main__":
app.run(port=port)
v5.13.1
v5.13.0
This release of the Nylas Python SDK includes a small change as well as the release of local webhook development support built directly into the SDK. When implementing this feature in your app, the SDK will create a tunnel connection to a websocket server and registers it as a webhook callback to your Nylas account. See below for a usage example.
Release Notes
Added
- Add local webhook development support (#252)
Changed
- Use PEP508 syntax for conditional dependencies (#250)
Usage
Webhook Tunnel
During the setup process you can pass in methods to override the websocket client's callback methods. The most important method is the on_message
method which returns a parsed delta event from the webhook server.
from client.restful_models import Webhook
from nylas import APIClient
from services.tunnel import open_webhook_tunnel
nylas = APIClient(
"CLIENT_ID",
"CLIENT_SECRET",
)
def run_webhook():
def on_message(delta):
if delta["type"] == Webhook.Trigger.MESSAGE_UPDATED:
print(delta)
def on_open(ws):
print("opened")
def on_error(ws, err):
print("Error found")
print(err)
open_webhook_tunnel(
nylas, {"on_message": on_message, "on_open": on_open, "on_error": on_error}
)
if __name__ == "__main__":
run_webhook()
Contributors 🎸
v5.12.1
v5.12.0
This release of the Nylas Python SDK brings a single addition.
Release Notes
Added
- Add support for sending raw MIME messages (#243)
Usage
Sending raw MIME messages
from nylas import APIClient
nylas = APIClient(
CLIENT_ID,
CLIENT_SECRET,
ACCESS_TOKEN
)
raw_mime = """MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Subject: With Love, From Nylas
From: You <[email protected]>
To: My Nylas Friend <[email protected]>
This email was sent via raw MIME using the Nylas email API. Visit https://nylas.com for details.
"""
draft = nylas.drafts.create()
# Send the raw MIME
msg = draft.send_raw(raw_mime)
v5.11.0
v5.10.2
v5.10.1
v5.10.0
This release of the Nylas Python SDK brings a few additions.
Release Notes
Added
- Add
metadata
field toJobStatus
(#227) - Add missing hosted authentication parameters (#229)
- Add support for
calendar
field in free-busy, availability, and consecutive availability queries (#228)
Using New Features
New calendars field in free-busy/availability queries
from nylas import APIClient
nylas = APIClient(
CLIENT_ID,
CLIENT_SECRET,
ACCESS_TOKEN
)
# Free busy with calendars
start_time = datetime.now()
end_time = datetime.now() + timedelta(hours = 24)
calendars = [{
"account_id": "test_account_id",
"calendar_ids": ["example_calendar_a", "example_calendar_b"]
}]
free_busy = nylas.free_busy("[email protected]", start_time, end_time, calendars)
# Availability with calendars
emails = ["[email protected]", "[email protected]", "[email protected]"]
start_time = datetime.now()
end_time = datetime.now() + timedelta(hours = 24)
duration = timedelta(minutes=30)
interval = timedelta(hours=1, minutes=30)
calendars = [{
"account_id": "test_account_id",
"calendar_ids": ["example_calendar_a", "example_calendar_b"]
}]
api_client.availability(emails, duration, interval, start_at, end_at, calendars=calendars)
# Consecutive availability with calendars
emails = [["[email protected]"], ["[email protected]", "[email protected]"]]
start_time = datetime.now()
end_time = datetime.now() + timedelta(hours = 24)
duration = timedelta(minutes=30)
interval = timedelta(hours=1, minutes=30)
calendars = [{
"account_id": "test_account_id",
"calendar_ids": ["example_calendar_a", "example_calendar_b"]
}]
api_client.consecutive_availability(emails, duration, interval, start_at, end_at, calendars=calendars)