Skip to content
j3k0Public

About

Customer Relationship Management from your Terminal

Resources

Stars

77 stars

Watchers

6 watching

Forks

Latest commit

 

History

120 Commits

Folders and files

Repository files navigation

crm-cli

A command-line Customer Relationship Management software.

  • Works as a standalone local cli tool or client / server for multi-users
  • With or withhout a database, supporting:
    • data as a singe JSON file
    • CouchDB

Who is it for?

The geek entrepreneur.

Why?

  • You own your data.
  • Use an open text-based format:
    • JSON it is.
    • You can create custom reporting tools.
    • You can create your own integrations (import, export, ...)
  • Open-source:
    • The code is very concise, hack into it!

Installation

npm install -g crm-cli

Usage

Get into the directory where you want your data to be stored. Something shared on Dropbox (or whatever) is a good idea.

The run the bellow command to initialize your data file.

crm init-crm

This creates a file called crm.json in the current directory. You can change the path to that file using the DATABASE_JSON_FILE environment variable (example: DATABASE_JSON_FILE=/home/user/crm.json)

The full list of commands supported by the tool is available by just entering crm on the command line.

usage: crm [--environment NAME|PATH] COMMAND [filter]

Available commands:

 - reports:

    i,interactions ... list of interactions.
    com,companies .... list of companies.
    con,contacts ..... list of contacts.
    a,apps ........... list of apps.
    about ............ all we know about a contact / company.
    f,followup ....... list of required follow-up.

 - data entry:

    add-company ............ register a new company.
    add-contact ............ register a new contact.
    add-app ................ register a new app.
    add-i,add-interaction .. register a new customer interaction.

    edit-company .............. edit an existing company.
    edit-contact .............. edit an existing contact.
    edit-app .................. edit an existing app.
    edit-i,edit-interaction ... edit an existing interaction.
    done ...................... remove follow-up date from interaction.

 - email:

    template FILE .......... fill in values for an email template.
    template-help .......... show the list of template fields.

 - system:

    init-crm ........ create data file in current directory.
    server .......... launch a CRM server.

Non-local usage

CRM cli also features a client server architecture.

You can launch a server:

export SERVER_API_KEY=$(openssl rand -hex 16) # at least 16 characters
export HOSTNAME=127.0.0.1 # that's the default
export PORT=3000
export DATABASE_URL=file://database.json
export ALLOW_RESET=1 # only needed for "crm init-crm" (POST /reset)
crm server

Then connect the CRM client to the server:

export DATABASE_URL=http://$SERVER_API_KEY@127.0.0.1:3000
# reset the database, or do whatever
crm init-crm

Server settings:

  • SERVER_API_KEY - the API key clients must send. The server refuses to start with a key shorter than 16 characters. If unset, a random key is generated and printed at startup: it changes on every restart, so existing clients get 401 until you set a fixed key.
  • ALLOW_RESET=1 - allow POST /reset to replace the database. Disabled by default; update_design_document (CouchDB) is always allowed. With file storage, the previous file is kept as <file>.before-reset-<date>.bak.

The CRM server doesn't support SSL and the API key travels in clear text: only expose it through a TLS-terminating reverse proxy, and use https:// URLs on the client side.

Environment files

Instead of exporting variables, put them in ~/.config/crm-cli/NAME.env (or $XDG_CONFIG_HOME/crm-cli/NAME.env) and select it with --environment NAME. There is no default environment: if env files exist and DATABASE_URL isn't set, crm lists them and exits.

# ~/.config/crm-cli/local.env
DATABASE_URL=http://myapikey@127.0.0.1:3000

Select a file by name or by path:

crm --environment local companies                # ~/.config/crm-cli/local.env
crm --environment ./envs/staging.env companies   # a value containing "/" or ending in ".env" is a path

Notes:

  • Real environment variables take precedence over the file (DATABASE_URL=memory:// crm companies still works).
  • A missing file given with --environment is an error.
  • Format: KEY=value lines, # comment lines, optional export prefix and quotes. No inline comments, no $VAR expansion.
  • Relative paths inside values (file://crm.json) are resolved from the current directory, not from the env file.
  • The file may contain secrets (API key, passwords): chmod 600 it.
  • crm init-crm uses the loaded DATABASE_URL, so with a remote one it resets the remote database.
  • The Docker image runs the server directly and doesn't read env files; use -e / ENV there.

Docker

You can run the server with docker.

docker run -p 8000:80 -e SERVER_API_KEY=$(openssl rand -hex 16) --rm -it jeko/crm-server

The container runs as the unprivileged node user (uid 1000): a data volume created by an older (root) image needs chown -R 1000:1000 first. Otherwise the server refuses to start (EACCES), because it can't save.

To build the image:

docker build -t jeko/crm-server .

By default it will use a local crm.json file stored in a volume mounted in /app/data.

You can customize the database with the DATABASE_URL environment variable.

Note on filters

All reports commands accepts a filter argument, used to restrict the data display.

The filter is a fuzzy case-insensitive operator.

Examples:

  • crm about microsoft will show all data you have about Microsoft.
  • crm about marc twain will show all data you have about Marc Twain.

Company display name

A company's name is its record key and can't be renamed. To show something friendlier, set the optional displayName (crm edit-company NAME):

  • crm companies has a displayName column and its filter matches it.
  • crm about shows Display Name (key name) and its filter matches it.
  • {{COMPANY_NAME}} (and {{FRIENDLY_NAME}} when a contact has no first name) use the display name in email templates.

Commands that look a company up by name (edit-company, the API's GET /companies/search/:filter, ...) still match the record key only.

Storing and showing the field needs no server upgrade: older servers store it as-is. Once the server runs this version, server-rendered templates use the display name too, and file-storage search matches it (CouchDB search still matches the key only).

DATABASE_URL

The DATABASE_URL environment variable sets the connection to the database.

Possible values:

  • file://PATH/TO-FILE.json - Relative path to a JSON file
  • file:///PATH/TO-FILE.json - Absolute path to a JSON file
  • http://USER:API_KEY@HOST:PORT - URL to a CRM server (see "server" command)
  • couchdb://USER:PASSWORD@HOSTNAME:5984/DATABASE_NAME - CouchDB over HTTP
  • couchdbs://USER:PASSWORD@HOSTNAME:5984/DATABASE_NAME - CouchDB over HTTPS
  • memory:// - Non-persistent in-memory database (for testing)

Best practices

  • Put the crm.json file in version control.

Template emails

Here is how I use the template feature.

I create a file that contains the headers and body of an email (see templates/subscriber-followup.txt for an example)

To initiate an email to our newly subscribed customer (Microsoftware in this example):

crm template tempates/fup-registration.txt Microsoftware > email.txt
neomutt -H email.txt

This will open a Draft in mutt with all fields replaced.

I guess not everyone uses neomutt, but it's easy to adjust to your need. You can simply paste the output of the crm template command and compose your email from gmail or whatever.

Data format

crm.json contains JSON formatted data.

The root element is an array of Companies.

Company

A Company has the following attributes:

  • name: string
  • url: string
  • address: string
  • contacts: array of Contacts
  • interactions: array of Interactions
  • apps: array of Apps

Contact

A Contact has the following attributes:

  • firstName: string
  • lastName: string
  • role: string
  • email: string

The email field is considered a primary key. Should appear in only 1 Contact across all Companies.

Interaction

An Interaction has the following attributes:

  • kind: string -- the type of interaction (email, github, automated, ...)
  • date: string -- date of the interaction (anything javascript Date constructor can parse)
  • from: string -- email address of the contact
  • summary: string -- short summary of the interaction
  • content: string (optional) -- full interaction
  • followUpDate: string (optional) -- when a follow-up is due

Apps

An App has the following attributes:

  • appName
  • plan
  • email
  • createdAt
  • upgradedAt
  • churnedAt

Apps is basically one of your products or subscription you're trying to sell... It's specific to my use case, if the tool is useful to others, we might make the App concept a little more generic.

Interested by the idea?

Am I launching a rock in the water by sharing this on github? Do you have some interest? Let me know!

PRs are welcome, of course.

Legal

About

Customer Relationship Management from your Terminal

Resources

Stars

77 stars

Watchers

6 watching

Forks

Releases

Packages

Used by

Contributors

Languages