-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #633 from appwrite/feat-messaging-create-sms-message
Add support for creating SMS messages
- Loading branch information
Showing
6 changed files
with
190 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/routes/console/project-[project]/messaging/message-[message]/smsPreview.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<script lang="ts"> | ||
import { CardGrid, Heading } from '$lib/components'; | ||
import { FormList, InputTextarea } from '$lib/elements/forms'; | ||
import { message } from './store'; | ||
import SMSPhone from '../smsPhone.svelte'; | ||
</script> | ||
|
||
<CardGrid> | ||
<div class="grid-1-2-col-1 u-flex-vertical u-cross-start u-gap-16"> | ||
<Heading tag="h6" size="7">Preview</Heading> | ||
<SMSPhone content={$message.data.content} /> | ||
</div> | ||
<svelte:fragment slot="aside"> | ||
<FormList> | ||
<InputTextarea | ||
id="message" | ||
label="Message" | ||
disabled={true} | ||
bind:value={$message.data.content}> | ||
</InputTextarea> | ||
</FormList> | ||
</svelte:fragment> | ||
|
||
<svelte:fragment slot="actions"> | ||
<!-- TODO: Add support for editing draft messages --> | ||
<!-- <Button disabled={$message.status !== 'draft'} on:click={() => console.log('click')} | ||
>Edit message</Button> --> | ||
</svelte:fragment> | ||
</CardGrid> |
14 changes: 14 additions & 0 deletions
14
src/routes/console/project-[project]/messaging/smsPhone.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<script lang="ts"> | ||
export let content = ''; | ||
</script> | ||
|
||
<!-- TODO: Style to look like a phone --> | ||
<div class="phone card is-only-desktop"> | ||
{content} | ||
</div> | ||
|
||
<style lang="scss"> | ||
.phone { | ||
inline-size: calc(320 * 1rem / 16); | ||
} | ||
</style> |
136 changes: 136 additions & 0 deletions
136
src/routes/console/project-[project]/messaging/wizard/smsFormList.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
<script context="module" lang="ts"> | ||
export async function createSMSMessage(params: EmailMessageParams) { | ||
const response = await sdk.forProject.client.call( | ||
'POST', | ||
new URL(sdk.forProject.client.config.endpoint + '/messaging/messages/sms'), | ||
{ | ||
'X-Appwrite-Project': sdk.forProject.client.config.project, | ||
'content-type': 'application/json', | ||
'X-Appwrite-Mode': 'admin' | ||
}, | ||
params | ||
); | ||
return response.json(); | ||
} | ||
</script> | ||
|
||
<script lang="ts"> | ||
import { messageParams, providerType, type EmailMessageParams, MessageStatuses } from './store'; | ||
import { | ||
Button, | ||
FormList, | ||
InputEmail, | ||
InputRadio, | ||
InputText, | ||
InputTextarea | ||
} from '$lib/elements/forms'; | ||
import { Pill } from '$lib/elements'; | ||
import { CustomId, Modal } from '$lib/components'; | ||
import { user } from '$lib/stores/user'; | ||
import { clickOnEnter } from '$lib/helpers/a11y'; | ||
import { ID } from '@appwrite.io/console'; | ||
import { sdk } from '$lib/stores/sdk'; | ||
import { ProviderTypes } from '../providerType.svelte'; | ||
import SMSPhone from '../smsPhone.svelte'; | ||
let showCustomId = false; | ||
let showTest = false; | ||
let selected = 'self'; | ||
let otherEmail = ''; | ||
async function sendTestSMS() { | ||
const email = selected === 'self' ? $user.email : otherEmail; | ||
createSMSMessage({ | ||
topics: $messageParams[ProviderTypes.Email]?.topics || [], | ||
targets: $messageParams[ProviderTypes.Email]?.targets || [], | ||
description: $messageParams[ProviderTypes.Email]?.description || 'Test message', | ||
status: MessageStatuses.PROCESSING, | ||
messageId: ID.unique(), | ||
// TODO: properly handle the test email address | ||
users: ['steven'], | ||
subject: $messageParams[ProviderTypes.Email]?.subject || '', | ||
content: $messageParams[ProviderTypes.Email]?.content || '', | ||
html: $messageParams[ProviderTypes.Email]?.html || false | ||
}); | ||
} | ||
$: otherEmail = selected === 'self' ? '' : otherEmail; | ||
</script> | ||
|
||
<div class="u-flex u-gap-24"> | ||
<FormList class="u-stretch"> | ||
<div class="u-colum-gap-2"> | ||
<InputTextarea | ||
id="message" | ||
label="Message" | ||
placeholder="Type here..." | ||
bind:value={$messageParams[$providerType]['content']}> | ||
</InputTextarea> | ||
<!-- TODO: Add support for draft messages --> | ||
<!-- <div class="u-flex u-main-end"> | ||
<Button text on:click={() => (showTest = true)}>Send test message</Button> | ||
</div> --> | ||
<Modal title="Send test message" bind:show={showTest} onSubmit={sendTestSMS} size="big"> | ||
<slot /> | ||
<InputRadio | ||
label={$user.phone} | ||
bind:group={selected} | ||
value="self" | ||
id="self" | ||
name="selected" /> | ||
<InputRadio | ||
label="Other" | ||
bind:group={selected} | ||
value="other" | ||
id="other" | ||
name="selected" | ||
fullWidth> | ||
<svelte:fragment slot="description"> | ||
Enter the phone number to which the test message will be | ||
<div | ||
on:click={() => (selected = 'other')} | ||
on:keyup|self={clickOnEnter} | ||
role="button" | ||
tabindex="0"> | ||
<InputEmail | ||
showLabel={false} | ||
id="email" | ||
label="Email" | ||
placeholder="Enter email" | ||
bind:value={otherEmail} /> | ||
</div> | ||
</svelte:fragment> | ||
</InputRadio> | ||
|
||
<svelte:fragment slot="footer"> | ||
<Button secondary on:click={() => (showTest = false)}>Cancel</Button> | ||
<Button submit>Send</Button> | ||
</svelte:fragment> | ||
</Modal> | ||
</div> | ||
<InputText | ||
id="description" | ||
label="Description" | ||
placeholder="Enter description" | ||
tooltip="Provide a summary of the message. Users won't see this description." | ||
bind:value={$messageParams[$providerType]['description']}> | ||
</InputText> | ||
{#if !showCustomId} | ||
<div> | ||
<Pill button on:click={() => (showCustomId = !showCustomId)} | ||
><span class="icon-pencil" aria-hidden="true" /><span class="text"> | ||
Message ID | ||
</span></Pill> | ||
</div> | ||
{:else} | ||
<CustomId | ||
bind:show={showCustomId} | ||
name="Message" | ||
bind:id={$messageParams[$providerType].messageId} | ||
autofocus={false} /> | ||
{/if} | ||
</FormList> | ||
<SMSPhone content={$messageParams[$providerType]['content']} /> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters