Skip to content

Commit bbc9f18

Browse files
committed
Docs copied from triggerdotdev/trigger.dev repo
1 parent f8233b4 commit bbc9f18

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+12603
-0
lines changed

.gitignore

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
postgres-data
4+
# dependencies
5+
node_modules
6+
.pnp
7+
.pnp.js
8+
9+
# testing
10+
coverage
11+
12+
# next.js
13+
.next/
14+
out/
15+
build
16+
dist
17+
packages/**/dist
18+
19+
# Tailwind
20+
apps/**/styles/tailwind.css
21+
packages/**/styles/tailwind.css
22+
23+
# misc
24+
.DS_Store
25+
*.pem
26+
27+
# debug
28+
npm-debug.log*
29+
yarn-debug.log*
30+
yarn-error.log*
31+
32+
# local env files
33+
.env.docker
34+
.docker/*.env
35+
.env.local
36+
.env.development.local
37+
.env.test.local
38+
.env.production.local
39+
40+
# turbo
41+
.turbo
42+
.vercel
43+
.cache
44+
.env
45+
.output
46+
apps/**/public/build
47+
.tests-container-id.txt

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Mintlify Starter Kit
2+
3+
Click on `Use this template` to quickstarter your documentation setup with Mintlify. The starter kit contains examples including
4+
5+
- Guide pages
6+
- Navigation
7+
- Customizations
8+
- API Reference pages
9+
- Use of popular components
10+
11+
### 👩‍💻 Development
12+
13+
Run these from the root of the repository
14+
15+
```
16+
pnpm install --filter docs
17+
```
18+
19+
```
20+
pnpm run dev --filter docs
21+
```
22+
23+
Go to http://localhost:3050
24+
25+
### 😎 Publishing Changes
26+
27+
Changes will be deployed to production automatically after pushing to the default branch.
28+
29+
You can also preview changes using PRs, which generates a preview link of the docs.
30+
31+
#### Troubleshooting
32+
33+
- Mintlify dev isn't running - Run `mintlify install` it'll re-install dependencies.
34+
- Mintlify dev is updating really slowly - Run `mintlify clear` to clear the cache.

_snippets/whatsapp-to-slack.mdx

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
The following example combines WhatsApp and Slack to create a workflow that allows you to receive WhatsApp messages in Slack, and use a modal to compose a reply.
2+
3+
<CodeGroup>
4+
5+
```tsx whatsappToSlack.tsx
6+
/** @jsxImportSource jsx-slack */
7+
import { Trigger } from "@trigger.dev/sdk";
8+
import {
9+
events,
10+
sendText,
11+
getMediaUrl,
12+
MessageEventMessage,
13+
} from "@trigger.dev/whatsapp";
14+
import JSXSlack, {
15+
Actions,
16+
Blocks,
17+
Button,
18+
Section,
19+
Header,
20+
Context,
21+
Image,
22+
Modal,
23+
Input,
24+
Textarea,
25+
} from "jsx-slack";
26+
import * as slack from "@trigger.dev/slack";
27+
28+
const dateFormatter = new Intl.DateTimeFormat("en-US", {
29+
timeStyle: "short",
30+
dateStyle: "short",
31+
});
32+
33+
// this trigger listens for WhatsApp messages and sends them to Slack
34+
new Trigger({
35+
id: "whatsapp-to-slack",
36+
name: "WhatsApp: load messages",
37+
on: events.messageEvent({
38+
accountId: "<account id>",
39+
}),
40+
run: async (event, ctx) => {
41+
//this generates Slack blocks from the WhatsApp message
42+
const messageBody = await createMessageBody(event.message);
43+
44+
await slack.postMessage("jsx-test", {
45+
channelName: "whatsapp-support",
46+
//text appears in Slack notifications on mobile/desktop
47+
text: "How is your progress today?",
48+
//import and use JSXSlack to make creating rich messages much easier
49+
blocks: JSXSlack(
50+
<Blocks>
51+
<Header>From: {event.message.from}</Header>
52+
<Context>At: {dateFormatter.format(event.message.timestamp)}</Context>
53+
{messageBody}
54+
<Actions blockId="launch-modal">
55+
<Button value="reply" actionId="reply">
56+
Reply
57+
</Button>
58+
</Actions>
59+
</Blocks>
60+
),
61+
//pass the WhatsApp message to the next trigger
62+
metadata: {
63+
whatsAppMessage: event.message,
64+
},
65+
});
66+
},
67+
}).listen();
68+
```
69+
70+
```tsx replyButtonInteraction.tsx
71+
//this trigger creates a Slack modal when a user presses the Reply button
72+
new Trigger({
73+
id: "whatsapp-to-slack-modal",
74+
name: "WhatsApp: show message composer",
75+
on: slack.events.blockActionInteraction({
76+
blockId: "launch-modal",
77+
}),
78+
run: async (event, ctx) => {
79+
if (!event.trigger_id) {
80+
return;
81+
}
82+
83+
//get the action (pressing the reply button) and the original WhatsApp message
84+
const action = event.actions[0];
85+
const whatsAppMessage =
86+
event.message?.metadata?.event_payload.whatsAppMessage;
87+
88+
//generate Slack blocks from the WhatsApp message
89+
const messageBody = await createMessageBody(whatsAppMessage);
90+
91+
if (action.action_id === "reply" && action.type === "button") {
92+
//show a reply modal, with the original message and an input field for the reply
93+
await slack.openView(
94+
"Opening view",
95+
event.trigger_id,
96+
JSXSlack(
97+
<Modal title="Your reply" close="Cancel" callbackId="submit-message">
98+
<Header>Original message</Header>
99+
{messageBody}
100+
<Header>Your reply</Header>
101+
<Textarea
102+
name="message"
103+
label="Message"
104+
placeholder="Your message"
105+
maxLength={500}
106+
id="messageField"
107+
/>
108+
<Input type="submit" value="submit" />
109+
</Modal>
110+
),
111+
{
112+
onSubmit: "close",
113+
//pass the original WhatsApp message to the next trigger, and the original Slack message so we can thread replies
114+
metadata: {
115+
whatsAppMessage,
116+
thread_ts: event.message?.ts,
117+
},
118+
}
119+
);
120+
}
121+
},
122+
}).listen();
123+
```
124+
125+
```tsx replyModalSubmission.tsx
126+
//this trigger sends the reply from Slack to WhatsApp
127+
new Trigger({
128+
id: "whatsapp-composed-slack-message",
129+
name: "WhatsApp: send message from Slack",
130+
on: slack.events.viewSubmissionInteraction({
131+
callbackId: "submit-message",
132+
}),
133+
run: async (event, ctx) => {
134+
await ctx.logger.info("Modal submission", { event });
135+
136+
//the message from the input field in Slack
137+
const usersResponse = event.view.state?.values.messageField.message
138+
.value as string;
139+
140+
//get the data from the previous messages/panels
141+
const privateMetadata =
142+
event.view.private_metadata && JSON.parse(event.view.private_metadata);
143+
await ctx.logger.info("Private metadata", privateMetadata);
144+
const whatsAppMessage = privateMetadata?.whatsAppMessage;
145+
146+
if (!whatsAppMessage || !usersResponse) {
147+
await ctx.logger.error("No message or original message", { event });
148+
return;
149+
}
150+
151+
//send WhatsApp message
152+
await sendText("send-whatsapp", {
153+
fromId: "102119172798864",
154+
to: whatsAppMessage.from,
155+
text: usersResponse,
156+
});
157+
158+
//send message in the Slack thread
159+
await slack.postMessage("slack-reply", {
160+
channelName: "whatsapp-support",
161+
text: `Replied with: ${usersResponse}`,
162+
blocks: JSXSlack(
163+
<Blocks>
164+
<Header>Reply from @{event.user.username}</Header>
165+
<Context>
166+
At: {dateFormatter.format(new Date())} To: {whatsAppMessage.from}
167+
</Context>
168+
<Section>{usersResponse}</Section>
169+
</Blocks>
170+
),
171+
thread_ts: privateMetadata?.thread_ts,
172+
});
173+
174+
return event;
175+
},
176+
}).listen();
177+
178+
//creates different Slack blocks depending on the type of WhatsApp message (e.g. text, image, etc.)
179+
async function createMessageBody(message: MessageEventMessage) {
180+
switch (message.type) {
181+
case "text": {
182+
return <Section>{message.text.body}</Section>;
183+
}
184+
case "image": {
185+
const mediaUrl = await getMediaUrl(`getImageUrl`, message.image);
186+
return (
187+
<Image
188+
src={mediaUrl}
189+
alt={message.image.caption ?? ""}
190+
title={message.image.caption ?? ""}
191+
/>
192+
);
193+
}
194+
case "video": {
195+
const mediaUrl = await getMediaUrl(`getVideoUrl`, message.video);
196+
return <Section>{mediaUrl}</Section>;
197+
}
198+
default:
199+
return <Section>Unsupported message type: {message.type}</Section>;
200+
}
201+
}
202+
```
203+
204+
</CodeGroup>

api-reference/events/sendEvent.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
title: "Send Event"
3+
openapi: "POST /events"
4+
sidebarTitle: "Send Event"
5+
description: "Send a custom event to Trigger through the API."
6+
---

changelog.mdx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
title: "Changelog"
3+
description: "We release features and fixes weekly! See some of the changes we have made."
4+
---
5+
6+
## Feb 6 2023 Release
7+
8+
#### app.trigger.dev
9+
10+
- Improved the onboarding experience for new users, as well as users creating a new workflow.
11+
- Test editor now suggests example JSON for `customEvent` and `webhookEvent` actions.
12+
- Added a support widget to the bottom right of the screen.
13+
14+
#### @trigger.dev/sdk - v0.2.12
15+
16+
- Added `runOnce` and `runOnceLocalOnly` functions to support running custom idempotent actions. [Docs](/functions/run-once)
17+
- We will now serialize and send the Zod schemas for `customEvent` and `webhookEvent` to trigger.dev to support better test JSON generation (using `json-schema-faker`).
18+
19+
#### @trigger.dev/slack - v0.1.19
20+
21+
- Added support for opening modal views and handling view submissions. See [openView](/integrations/apis/slack/actions/open-view) and [viewSubmissionInteraction](/integrations/apis/slack/events/view-submission-interaction) docs for more info.
22+
- Added support for triggering on BlockKit actions and posting responses. See [blockActionInteraction](/integrations/apis/slack/events/block-action-interaction) and [postMessageResponse](/integrations/apis/slack/actions/post-message-response) docs for more info.
23+
- Added ability to add reactions to messages. See [addReaction](/integrations/apis/slack/actions/add-reaction) docs for more info.
24+
- You can now post a message in a thread using the `thread_ts` option in [postMessage](/integrations/apis/slack/actions/post-message).
25+
26+
#### @trigger.dev/whatsapp - v0.1.17
27+
28+
Initial release of our WhatsApp integration. Includes support for sending and receiving messages. See the [docs](/integrations/apis/whatsapp) for more info.

examples/examples.mdx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
title: "Example workflows"
3+
sidebarTitle: "Overview"
4+
description: "Example workflows to use in your projects."
5+
---
6+
7+
Not sure what to build? Take a look through our examples for inspiration.
8+
You can use these workflows in your product by following the instructions on each page.
9+
10+
<CardGroup>
11+
<Card title="GitHub" icon="github" href="/examples/github">
12+
When a GitHub repo is starred, post information about the user to Slack
13+
</Card>
14+
<Card title="Shopify" icon="shopify" href="/examples/shopify">
15+
Create a new product in my Shopify store.
16+
</Card>
17+
<Card title="Slack" icon="slack" href="/examples/slack">
18+
Post to Slack when a GitHub issue is created or modified.
19+
</Card>
20+
<Card title="Resend" icon="envelope" href="/examples/resend">
21+
Create a welcome email drip campaign.
22+
</Card>
23+
<Card title="WhatsApp" icon="whatsapp" href="/examples/whatsapp">
24+
Listen for WhatsApp messages and reply.
25+
</Card>
26+
</CardGroup>

0 commit comments

Comments
 (0)