Porting a serverless chatbot from Python to Rust

This page summarizes the projects mentioned and recommended in the original post on dev.to

Our great sponsors
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern identity platform for B2B SaaS
  • SaaSHub - Software Alternatives and Reviews
  • rustsec

    RustSec API & Tooling

  • The overall experience of writing Rust is made much more enjoyable because of the developer tooling. Everything revolves around Cargo which makes documentation, dependency management, linting, testing, and builds all part of the core language. Installing Rust using the standard rustup command also includes Cargo and there are several useful extras like Clippy and Audit.

  • Rocket

    A web framework for Rust.

  • Unable to get it to work, I switched to Rocket. This is being updated to support the new Rust async features but for now is synchronous. I guessed it would solve my problem with the Mailchimp Crate not working properly with async code, and it did seem to solve the issue. This was too difficult to debug as a Rust newbie.

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

    InfluxDB logo
  • actix-web

    Actix Web is a powerful, pragmatic, and extremely fast web framework for Rust.

  • I started with Actix, which uses the relatively new support for asynchronous Rust programming, but couldn't get it working with the non-async Mailchimp crate. I tried writing my own basic calls using the built-in async HTTP client but that doesn't support HTTPS connections without a feature flag. There is example code but it states "As of actix-web 2.0.0, one must be very careful about setting up https communication" without explaining what that setup involves. I saw strange behaviour with initial requests timing out then subsequent requests succeeding, which I assumed was to do with async.

  • aws-lambda-rust-runtime

    A Rust runtime for AWS Lambda

  • All languages have a range of frameworks that help building web endpoints, often with an embedded web server. Rust has Actix and Rocket, amongst others. By creating generic HTTP endpoints, the application can be run anywhere. AWS Lambda has some experimental Rust language bindings, but creating a set of generic web endpoints is better because it is not then tied to a specific platform.

  • bc3-api

    API documentation for Basecamp 4

  • Like most chat products Basecamp has a bot API to send arbitrary messages into the chat. It is therefore easy to use the Mailchimp API to pull the stats and post them into Basecamp. This code just needs to run every morning.

  • muslrust

    Docker environment for building musl based static linux rust binaries

  • After a lot of searching I came across a Docker image which provides a clean environment for building Rust linked against musl libc. It includes curl, pq, sqlite3, and zlib, but the main one I needed was OpenSSL. This container image solved my problem and I can run using Docker locally as well as in the GitHub Action build workflow.

  • bc-totorobot

    Discontinued A bot to post stats into the Console Basecamp chat room. Rust version.

  • The bot code is available open source on GitHub and I will continue to work on improvements in my spare time. It needs more testing and probably some refactoring to avoid deliberate panics.

  • WorkOS

    The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.

    WorkOS logo
  • Iron

    An Extensible, Concurrent Web Framework for Rust

  • There are several web frameworks for Rust: Rocket, Actix, Warp, Iron - but only Actix has released a stable 1.0 release, and there has been considerable controversy over how it uses unsafe Rust.

  • mailchimp-marketing-python

    The official Python client library for the Mailchimp Marketing API

  • I have been writing Python for over 10 years, so it was the default choice to create a simple serverless bot. Azure has native Python support, the Basecamp API takes a simple HTTP POST, and Mailchimp has an official Python SDK.

  • rust.vim

    Vim configuration for Rust.

  • I'm a vim user so the official rust.vim plugin gives me autocomplete and in-editor checks, but the output from Cargo (warnings and errors) is very helpful and pinpointing problems. rust-clippy is fun, too.

  • upx-action

    Strips and runs upx on binaries

  • It is currently convenient to run this bot on Azure, but it would be trivial to move it to AWS or a generic web server. Using upx to compress the executable means the final binary with a full embedded web server is just 2.5MB. This application is so lightweight it could even run on a Raspberry Pi in the office - I'd just need to compile it for ARM.

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts