Skip to content

Commit

Permalink
chore: make subject configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
leggetter committed Feb 15, 2024
1 parent 38963a6 commit 7d83f16
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .env-example
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ FROM_EMAIL=
# Potentially the same as the FROM_EMAIL
TO_EMAIL=

# The subject used in the email conversations
SUBJECT=

# The SMS participant for messages to be sent to
TO_NUMBER=

Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ Update the contents as described below:
- `FROM_NUMBER`: Within the Vonage dashboard open **Numbers** -> **Your Numbers**.
- `HOOKDECK_API_KEY`: See [Hookdeck workspace docs](https://hookdeck.com/docs/workspaces?ref=github-omnitext#api-key)
- `VONAGE_API_KEY` and `VONAGE_API_SECRET`: You'll see these credentials at the very top of the Vonage API dashboard home page.
`POSTMARK_SERVER_API_TOKEN`: From the Postmark dashboard, select your Postmark server and then select **API Tokens**. The token is in the **Server API** section.
- `POSTMARK_SERVER_API_TOKEN`: From the Postmark dashboard, select your Postmark server and then select **API Tokens**. The token is in the **Server API** section.
- `SUBJECT`: The subject used in the email

Run the `push.mjs` script to create two connections in Hookdeck to manage the omnichannel and omnidirectional communication between SMS via Vonage and email via Postmark:

```
node push.mjs
npm run push
```

The output will be similar to the following:
Expand All @@ -66,11 +67,11 @@ Head to your workspace in Hookdeck and you will see two [connections](https://ho

![Two connections in the Hookdeck dashboard](docs/omnitext-connections.png)

Head to the Vonage Dashboard, select **Numbers** -> **Your Numbers**, and click the pencil icon under the **Manage** column for your Vonage phone number. Set the SMS Inbound Webhook URL to one indicated in the `node push.mjs` output.
Head to the Vonage Dashboard, select **Numbers** -> **Your Numbers**, and click the pencil icon under the **Manage** column for your Vonage phone number. Set the SMS Inbound Webhook URL to one indicated in the `npm run push` output.

![Set your Vonage phone number webhook URL](docs/vonage-phone-number-config.png)

Head to your Postmark dashboard, select your Postmark server, select the **Default Inbound Stream** -> **Settings**, and set your **Inbound webhook** to the one indicated in the `node push.mjs` output.
Head to your Postmark dashboard, select your Postmark server, select the **Default Inbound Stream** -> **Settings**, and set your **Inbound webhook** to the one indicated in the `npm run push` output.

![Postmark Webhook config](docs/postmark-webhooks-config.png)

Expand Down
3 changes: 2 additions & 1 deletion __tests__/transformations.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const resetEnvVars = () => {
process.env.TO_EMAIL = "[email protected]";
process.env.TO_NUMBER = "447700900000";
process.env.FROM_NUMBER = "447700900001";
process.env.SUBJECT = "A great conversation!";
};

beforeEach(resetEnvVars);
Expand Down Expand Up @@ -60,7 +61,7 @@ describe("SMS to Email", () => {

expect(transformedRequest.body.TextBody).toEqual(smsTextValue);
expect(transformedRequest.body.MessageStream).toEqual("outbound");
expect(transformedRequest.body.Subject).toEqual("Conversation {{topic}}");
expect(transformedRequest.body.Subject).toEqual(process.env.SUBJECT);
expect(transformedRequest.body.Headers.length).toEqual(1);
});

Expand Down
7 changes: 4 additions & 3 deletions src/transformations/vonage-sms-to-postmark-email.mjs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
const smsToEmail = (request, context) => {
const replayToEmail = process.env.REPLY_TO_EMAIL;
const replyToEmail = process.env.REPLY_TO_EMAIL;
const fromEmail = process.env.FROM_EMAIL;
const toEmail = process.env.TO_EMAIL;
const subject = process.env.SUBJECT;

const domain = toEmail ? toEmail.replace(/.*@/, "") : "example.com";
const conversationId = `<omnitext/conversation/1@${domain}>`;

const postmarkSendEmailRequest = {
From: fromEmail,
To: toEmail,
ReplyTo: replayToEmail,
Subject: `Conversation {{topic}}`,
ReplyTo: replyToEmail,
Subject: subject,
TextBody: request.body.text,
MessageStream: "outbound",

Expand Down

0 comments on commit 7d83f16

Please sign in to comment.