# Railway

## What is Railway?

Railway is a deployment platform where you can provision infrastructure, develop with that infrastructure locally, and then deploy to the cloud.

## Requirements

* A credit card.
* An email account.
* A [GitHub](https://github.com/signup) account.
* You have completed the initial steps: [invited your bot](https://docs.modmail.dev/installation/..#create-a-discord-bot) and [created a MongoDB database](https://docs.modmail.dev/installation/..#create-a-mongodb-database).

## Costs

Their lowest plan starts at $5 per month. Visit the [pricing](https://railway.app/pricing) page for the up-to-date pricing info.

## Fork our GitHub repositories

You will need to fork our repositories to deploy onto Railway.

Make sure you're logged in to [GitHub](https://github.com/). You will need to fork **two** repositories.

First we fork the Modmail repository. Head over to <https://github.com/modmail-dev/modmail/fork>, leave all the settings as default, and click **Create fork**.

<figure><img src="https://2552393832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYNLvoDNVxNyJfZ4x44Yz%2Fuploads%2Fgit-blob-8b62bf29f2525e1e5ad0edaef23b93d530562cd1%2FRW1.png?alt=media" alt="Screenshot of creating a Modmail fork."><figcaption><p>Create a GitHub fork for the Modmail Repository.</p></figcaption></figure>

Next do the same for the Logviewer repository by heading over to <https://github.com/modmail-dev/logviewer/fork>, leave all the settings as default, and click **Create fork**.

<figure><img src="https://2552393832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYNLvoDNVxNyJfZ4x44Yz%2Fuploads%2Fgit-blob-02ddf9cfac3009bf1c39212a386fdffc984e8947%2FRW2.png?alt=media" alt="Screenshot of creating a Logviewer fork."><figcaption><p>Create a GitHub fork for the Logviewer Repository.</p></figcaption></figure>

Next, to keep your Modmail and Logviewer up to date, you will need to install the [Pull app](https://github.com/apps/pull). Simply head over to <https://github.com/apps/pull>, click **Install**, choose **Only select repositories**, then select **both** the Modmail and Logviewer repositories that you forked in the previous step.

<div><figure><img src="https://2552393832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYNLvoDNVxNyJfZ4x44Yz%2Fuploads%2Fgit-blob-3b6664e5bcd3eb33083f3608a1724a1367b869ef%2FRW3.png?alt=media" alt="Screenshot of installing the pull app."><figcaption><p>Click <strong>Install</strong> to install the <a href="https://github.com/apps/pull">Pull app</a>.</p></figcaption></figure> <figure><img src="https://2552393832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYNLvoDNVxNyJfZ4x44Yz%2Fuploads%2Fgit-blob-b237bb51c0ad5dab18e8090075e9aa0b9bb5083a%2FRW4.png?alt=media" alt="Screenshot of selecting both repositories."><figcaption><p>Select <strong>both</strong> the Modmail and Logviewer forks, then click <strong>Install</strong>.</p></figcaption></figure></div>

Your GitHub should now be all set. Next step, [create a Railway account](#create-a-railway-account) to deploy your bot.

## Create a Railway account

Head over to [Railway's website](https://railway.app/new) and create an account. It will ask you to create a new project, choose **Deploy from GitHub repo**. Then, you will be asked to connect your GitHub account.

{% embed url="<https://railway.app/new>" %}
Sign up for a new Railway account.
{% endembed %}

<figure><img src="https://2552393832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYNLvoDNVxNyJfZ4x44Yz%2Fuploads%2Fgit-blob-44f68625e3516a47e504c64b9004d494f8bdfc92%2FRW5.png?alt=media" alt="Screenshot of selecting the deploy from GitHub repo option."><figcaption><p>Choose <strong>Deploy from GitHub repo</strong> when creating a new project.</p></figcaption></figure>

<details>

<summary>Why does it says "Your Account is Unverified"?</summary>

If your GitHub account is new or not reputable, you may be asked to verify your identify.

This unfortunately means that you will have to provide a credit card for verification. Click **Verify Account**, read and accept Railway's **Terms of Service**, then enter your credit card details. You may be temporary charged $1 USD to confirm the legitimacy of the card.

![Screenshot of clicking verify account.](https://2552393832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYNLvoDNVxNyJfZ4x44Yz%2Fuploads%2Fgit-blob-e34dae08e44806270148b21d7a646bdbbf7fb705%2FRW6.png?alt=media) ![Screenshot of clicking terms of service.](https://2552393832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYNLvoDNVxNyJfZ4x44Yz%2Fuploads%2Fgit-blob-d2258d87fc56d44eb774360eb138af1cb8a9607f%2FRW7.png?alt=media) ![Screenshot of clicking I agree with terms of service.](https://2552393832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYNLvoDNVxNyJfZ4x44Yz%2Fuploads%2Fgit-blob-e5a02cf085afc3559a51ad2c9f7df6c561ea51b1%2FRW7B.png?alt=media) ![Screenshot of entering your credit card details.](https://2552393832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYNLvoDNVxNyJfZ4x44Yz%2Fuploads%2Fgit-blob-55352801c9151db0ddb2f35ba229107ed8b92cb6%2FRW8.png?alt=media)

</details>

Next, you will be asked to **Configure a GitHub App**. You will be directed to the GitHub authentication page. Choose **Only select repositories**, then select **both** the Modmail and Logviewer repositories, as you have done before. Finally, click **Install & Authorize**.

<div><figure><img src="https://2552393832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYNLvoDNVxNyJfZ4x44Yz%2Fuploads%2Fgit-blob-884b9eb76316530d4d12f7638683d09addd3305f%2FRW9.png?alt=media" alt="Screenshot of choosing configure GitHub app."><figcaption><p>Click <strong>Configure a GitHub App</strong>.</p></figcaption></figure> <figure><img src="https://2552393832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYNLvoDNVxNyJfZ4x44Yz%2Fuploads%2Fgit-blob-e87c7df961a6a9c46294085cb6cf6fb17026cb5d%2FRW10.png?alt=media" alt="Screenshot of selecting both repositories."><figcaption><p>Select <strong>both</strong> the Modmail and Logviewer forks, then click <strong>Install &#x26; Authorize</strong>.</p></figcaption></figure></div>

The next step is to deploy Modmail onto Railway. This is split into two parts. You will need to complete **both parts** to fully Modmail.

## Part 1: Deploying the Logviewer

From the [**New Project**](https://railway.app/new) page, create the project by selecting your **Logviewer** repository, then select **Add variables**.

<div><figure><img src="https://2552393832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYNLvoDNVxNyJfZ4x44Yz%2Fuploads%2Fgit-blob-8828532d71c08115c41d9fc68d326a8ad4c74c4f%2FRW11B.png?alt=media" alt="Screenshot of selecting the Logviewer repository."><figcaption><p>Choose your <strong>Logviewer</strong> repository fork.</p></figcaption></figure> <figure><img src="https://2552393832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYNLvoDNVxNyJfZ4x44Yz%2Fuploads%2Fgit-blob-254555c32e7fbf46ed71bcae297d1f275c9de3b3%2FRW12B.png?alt=media" alt="Screenshot of choosing Add Variables."><figcaption><p>Click on <strong>Add variables</strong>. Alternatively, the following page can also be found within the project -> variables menu.</p></figcaption></figure></div>

Click **New Variable**, set left to be **`CONNECTION_URI`**, then on the right, paste your revised MongoDB connection string from your Notepad (if this is new to you, [go back and read the initial steps](https://docs.modmail.dev/installation)).

Don't add any other variables, nor use the suggested variables section. You should see a new variable named **`CONNECTION_URI`** added under variables once you're done.

<div><figure><img src="https://2552393832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYNLvoDNVxNyJfZ4x44Yz%2Fuploads%2Fgit-blob-d57e84066e3230e73436f2134e73d73e025fb4f3%2FRW13.png?alt=media" alt="Screenshot of clicking new variable."><figcaption><p>Click on <strong>New Variable</strong>.</p></figcaption></figure> <figure><img src="https://2552393832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYNLvoDNVxNyJfZ4x44Yz%2Fuploads%2Fgit-blob-b9831a84d521ad0fcc55a73873df28957de9e646%2FRW14.png?alt=media" alt="Screenshot of filling left and right boxes then click add."><figcaption><p>Left side: <strong><code>CONNECTION_URI</code></strong>. Right side: your <strong>MongoDB connection string</strong>. Then click <strong>+ Add</strong>.</p></figcaption></figure> <figure><img src="https://2552393832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYNLvoDNVxNyJfZ4x44Yz%2Fuploads%2Fgit-blob-cf6f3e1c6ea72ffbdf579110ff9101b32b188d85%2FRW15.png?alt=media" alt="Screenshot of the completed variables page."><figcaption><p>Once you've added the variable, you should see a single variable named <strong><code>CONNECTION_URI</code></strong>.</p></figcaption></figure></div>

Next, go to the **Deployments** tab, look at the latest deployment, is it successful? You may need to wait up to 10 minutes. If you click the URL, you should be taken to your Logviewer homepage (see screenshot below). **Save this URL** into your Notepad as we will need it for the next step, we will be referring to this as your Logviewer URL.

<div><figure><img src="https://2552393832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYNLvoDNVxNyJfZ4x44Yz%2Fuploads%2Fgit-blob-86f0d57f5c482a0743741f466333683a42fe2362%2FRW16.png?alt=media" alt="Screenshot of the deployments tab, and clicking the URL."><figcaption><p>Navigate to the <strong>Deployments</strong> tab, save and open this URL.</p></figcaption></figure> <figure><img src="https://2552393832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYNLvoDNVxNyJfZ4x44Yz%2Fuploads%2Fgit-blob-83a044aa0a74798d2f522ea74451b4440b4ead9e%2FLVHOME.png?alt=media" alt="Screenshot of the Logviewer homepage."><figcaption><p>This URL should show the Logviewer homepage.</p></figcaption></figure></div>

## Part 2: Deploying the Modmail bot

From the [**New Project**](https://railway.app/new) page, create the project by selecting your **Modmail** repository, then select **Add variables**.

<div><figure><img src="https://2552393832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYNLvoDNVxNyJfZ4x44Yz%2Fuploads%2Fgit-blob-d6cc4ad325fb1f7b3e45800041f8dc0e8a0bad3b%2FRW11.png?alt=media" alt="Screenshot of selecting the Modmail repository."><figcaption><p>Choose your <strong>Modmail</strong> repository fork.</p></figcaption></figure> <figure><img src="https://2552393832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYNLvoDNVxNyJfZ4x44Yz%2Fuploads%2Fgit-blob-959094de2257af5021b325d5589db41c7d635041%2FRW12.png?alt=media" alt="Screenshot of choosing Add Variables."><figcaption><p>Click on <strong>Add variables</strong>. Alternatively, the following page can also be found within the project -> variables menu.</p></figcaption></figure></div>

Click **New Variable.** We will be adding 5 variables in total, so repeat this step until you've added all 5 variables.

<table><thead><tr><th>Variable Name (left)</th><th>Variable Value (right)</th><th>Example</th></tr></thead><tbody><tr><td><strong><code>CONNECTION_URI</code></strong></td><td>The MongoDB Connection string from your Notepad.</td><td><pre data-overflow="wrap"><code>mongodb+srv://modmail:elAO7wF1r07pNG6u@cluster0.example.mongodb.net
</code></pre></td></tr><tr><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td></tr><tr><td><strong><code>TOKEN</code></strong></td><td>The Discord bot token from your Notepad.</td><td><pre data-overflow="wrap"><code>MTA3Djv3IAxNjk1NDgdKD231.G1AoUjD.5z629aKP34JKHn4v1EsdNUwdDO3MvBR9ifVES4
</code></pre></td></tr><tr><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td></tr><tr><td><strong><code>LOG_URL</code></strong></td><td>The Logviewer URL from your Notepad. Remember to add <code>https://</code> in front!</td><td><pre data-overflow="wrap"><code><strong>https://web-production-1234.up.railway.app
</strong></code></pre></td></tr><tr><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td></tr><tr><td><strong><code>OWNERS</code></strong></td><td>Your Discord ID. If you have multiple owners, separate your IDs with a comma.</td><td><pre><code>718827787302791100
</code></pre></td></tr><tr><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td></tr><tr><td><strong><code>GUILD_ID</code></strong></td><td>The ID of the Discord server for your Modmail bot.</td><td><pre><code>109483701365508619
</code></pre></td></tr><tr><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td></tr></tbody></table>

<details>

<summary>Do you have a separate staff server?</summary>

If you manage a large server where you have a separate server for communication among your moderation team, Modmail supports directing threads into the staff server instead of your main (public) server.

Simply add an additional variable named **`MODMAIL_GUILD_ID`** and set the value to your staff server's ID.

Note: the **`GUILD_ID`** should always be your main server's ID (not staff server's).

If you haven't yet invited your Modmail bot to your staff server, see the [invite section](https://docs.modmail.dev/installation/..#do-you-have-a-separate-staff-server).

</details>

<div><figure><img src="https://2552393832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYNLvoDNVxNyJfZ4x44Yz%2Fuploads%2Fgit-blob-184fc83e06b3fe1d3fd216a63dbf735481c419ad%2FRW17.png?alt=media" alt="Screenshot of clicking new variable."><figcaption><p>Click on <strong>New Variable</strong>.</p></figcaption></figure> <figure><img src="https://2552393832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYNLvoDNVxNyJfZ4x44Yz%2Fuploads%2Fgit-blob-8e44fc11945eebc6025a9105f158ec03842cd5a6%2FRW18.png?alt=media" alt="Screenshot of the completed variables page."><figcaption><p>Once you've added the variable as per the table above, you should see 5 variables here.</p></figcaption></figure></div>

## Complete the setup

Within 10 minutes of saving the Modmail bot variables, your Modmail bot should come online in your server. The default prefix for Modmail is **`?`**. You need to run **`?setup`** within your server to complete the setup. If you configured Modmail to use a separate staff server, you must run this command **in your staff server**. This will create a category for your Modmail threads and a Logs channel for an archive of all past threads.

<details>

<summary>Help! My bot hasn't started after 10 minutes.</summary>

This probably means you've failed to follow one or more steps. \[more info TODO]

</details>

## How to keep your bot running 24/7

You have 10 days to test Modmail without upgrading to the "Developer" plan. As mentioned in the [costs](#costs) section, Railway's Developer plan provides enough free monthly credits to run Modmail for **free** 24/7 everyday. However, you will need to provide your credit card details to upgrade your plan. More details can be found [here](https://docs.railway.app/reference/plans).

#### Usage-based subscription

Head over to the \*\*\*\* [**Billing Details**](https://railway.app/account/billing) page, click the **Unlock** button to unlock Developer plan. Then input your credit card details and hit **Subscribe to Developer Plan**.

{% hint style="warning" %}
Subscribing to the Developer plan under *usage based subscription* **may incur you unexpected charges**. This because Railway does not provide any safe-guards or monthly spending limits. Average Modmail and Logviewer usage should be well below the free threshold. However, if you run resource-intensive code via plugins or due to other means, you credit card may be billed.

If you want to guarantee that your credit card won't get charged for whatever reason, check out the [credit-based subscription model](#credit-based-subscription-alternative-subscription-model) instead. Alternatively, you can use a virtual credit card, such as [privacy.com](https://privacy.com/virtual-card), to verify for the Developer plan.
{% endhint %}

<div><figure><img src="https://2552393832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYNLvoDNVxNyJfZ4x44Yz%2Fuploads%2Fgit-blob-5052d9b15a4a2b4ae0481ecad55d62fc798c3172%2FRW20.png?alt=media" alt="Screenshot of clicking the unlock button."><figcaption><p>Click the <strong>Unlock</strong> button next to <strong>Unlock Developer Plan</strong>.</p></figcaption></figure> <figure><img src="https://2552393832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYNLvoDNVxNyJfZ4x44Yz%2Fuploads%2Fgit-blob-df08e3fd48225ab7a2e1d2c16f046fa7dfc6e22f%2FRW21.png?alt=media" alt="Screenshot of filling in credit card details and clicking subscribe."><figcaption><p>Fill in your credit card details then click <strong>Subscribe to Developer Plan</strong>.</p></figcaption></figure></div>

<details>

<summary>Why was I charged $1.00 USD?</summary>

This should be a temporary charge to verify that your credit card works as expected. Railway explains this with:

A temporary hold of $1.00 USD will be placed on the card and then refunded immediately.

</details>

#### Credit-based subscription (alternative subscription model)

If you rather pay a one-time $5.00 USD non-refundable credit purchase instead of permanently linking your credit card, you can choose to use the credit-based subscription model. As long as you have a non-zero credit balance (which should be forever since the monthly operating cost for Modmail is $0.00), you will be continuously subscribed to the Developer plan.

<div><figure><img src="https://2552393832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYNLvoDNVxNyJfZ4x44Yz%2Fuploads%2Fgit-blob-5052d9b15a4a2b4ae0481ecad55d62fc798c3172%2FRW20.png?alt=media" alt="Screenshot of clicking the unlock button."><figcaption><p>Click the <strong>Unlock</strong> button next to <strong>Unlock Developer Plan</strong>.</p></figcaption></figure> <figure><img src="https://2552393832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYNLvoDNVxNyJfZ4x44Yz%2Fuploads%2Fgit-blob-94310d15a08d5a4dd04259eeb80944d8650fdbaa%2FRW23.png?alt=media" alt="Screenshot of clicking credit-based subscription."><figcaption><p>Click <strong>Credit-based subscription</strong> at the bottom.</p></figcaption></figure> <figure><img src="https://2552393832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYNLvoDNVxNyJfZ4x44Yz%2Fuploads%2Fgit-blob-f84c93fad7fc7a75d48969788f1fc91942e9e0f3%2FRW24.png?alt=media" alt="Screenshot of entering credit card info, $5 amount, and click purchase credits."><figcaption><p>Fill in your credit card details, enter <strong>$5.00</strong> as the amount (it's the minimum), then click <strong>Purchase Credits</strong>.</p></figcaption></figure></div>

There you go! Your bot should now be able to run 24/7 without interruptions. Head over to the [**Usage**](https://railway.app/account/usage) page to make sure you won't be charged. Add up the estimated price for both your projects and verify that they're well below $5.00 USD.

<figure><img src="https://2552393832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYNLvoDNVxNyJfZ4x44Yz%2Fuploads%2Fgit-blob-2ea2b5220bcec6246e7499f0ce078a6f5f1c11b0%2FRW22.png?alt=media" alt="Screenshot of the usage page."><figcaption><p><strong>Estimated Bill</strong> should be $0.00 and the sum of the <strong>Estimated</strong> should be well below $5.00.</p></figcaption></figure>

<details>

<summary>How do I cancel my Developer plan subscription?</summary>

If you're subscribed under the [usage-based subscription](#usage-based-subscription) model, you can cancel your subscription by heading to the \*\*\*\* [**Billing Details**](https://railway.app/account/billing) page, click **Manage Subscription**, then click **Cancel plan**.

![Screenshot of clicking manage subscription.](https://2552393832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYNLvoDNVxNyJfZ4x44Yz%2Fuploads%2Fgit-blob-877f319f71396024abbb89c2639f28e709dec047%2FRW25.png?alt=media) ![Screenshot of clicking cancel plan.](https://2552393832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYNLvoDNVxNyJfZ4x44Yz%2Fuploads%2Fgit-blob-c427bf000258e6c8733d3e8a68f26172fb6986af%2FRW26.png?alt=media)

</details>

## Updating

Railway is configured to automatically update your Modmail bot and Logviewer whenever new updates become available.

<details>

<summary>How do I disable auto-updates?</summary>

You can disable auto-updates by heading to the settings page for **both** your Modmail and Logviewer projects. Under **Automatic Deployments**, click **Disable trigger**. ![Screenshot of disabling auto updates for Logviewer.](https://2552393832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYNLvoDNVxNyJfZ4x44Yz%2Fuploads%2Fgit-blob-eeb56b42b0219a3323da32da3c55ede31abd5b81%2FRW19b.png?alt=media)![Screenshot of disabling auto updates for Modmail.](https://2552393832-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYNLvoDNVxNyJfZ4x44Yz%2Fuploads%2Fgit-blob-fc9874c9646e44d8be7127a8725b474dd7b751f3%2FRW19a.png?alt=media)

</details>

## Next steps

Now that you've successfully set up Modmail, visit the [Getting Started](https://docs.modmail.dev/getting-started) page to find information on using Modmail.

You can also join our [**Discord Server**](https://discord.gg/cnUpwrnpYb) to interact with our community or get support for Modmail.
