Skip to content

feature/connector-http-sms #7510

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: master
Choose a base branch
from

Conversation

michakfromparis
Copy link

Summary

This PR adds a new HTTP SMS connector that allows sending SMS messages via HTTP API calls, following the exact same pattern and architecture as the existing HTTP email connector.

Features

  • Generic HTTP SMS delivery: Send SMS messages to any HTTP endpoint that accepts JSON payloads
  • Full payload forwarding: Passes the complete SendMessageData structure (to, type, payload) to external SMS services
  • Maximum genericity: Supports all template types and payload structures, including rich context information (application, organization, user data)
  • Simple configuration: Only requires an HTTP endpoint and optional authorization header
  • Consistent architecture: Mirrors the HTTP email connector implementation exactly

Implementation Details

  • Package: @logto/connector-http-sms
  • Type: SMS Connector implementing SmsConnector interface
  • Dependencies: Same as HTTP email connector (@logto/connector-kit, got, zod)
  • Payload format: Sends complete SendMessageData to configured endpoint as JSON
  • Error handling: Identical HTTP error handling and validation patterns
  • Authorization: Supports optional Authorization header for API authentication

File Structure

packages/connectors/connector-http-sms/
├── src/
│   ├── index.ts           # Main connector implementation
│   ├── types.ts           # TypeScript type definitions
│   ├── constant.ts        # Metadata and form configuration
│   ├── mock.ts            # Mock data for testing
│   └── index.test.ts      # Unit tests
├── package.json           # Dependencies and scripts
├── README.md              # Documentation
├── CHANGELOG.md           # Version history
├── logo.svg               # SMS-themed logo
├── logo-dark.svg          # Dark theme logo

Configuration

The connector accepts a simple configuration:

{
  "endpoint": "https://example.com/sms-api",
  "authorization": "Bearer your-token" // optional
}

Payload Example

When sending an SMS, the connector forwards the complete Logto message data:

{
  "to": "+1234567890",
  "type": "SignIn",
  "payload": {
    "code": "123456",
    "locale": "en-US",
    // ... any additional context data
  }
}

This design allows external SMS services to handle template rendering, localization, and business logic while providing full access to Logto's rich context data.

Testing

Unit Tests

  • Connector initialization: Verifies the connector can be created without errors
  • HTTP endpoint calls: Tests that the correct payload is sent to the configured endpoint
  • Payload structure validation: Ensures the sent payload matches expected SendMessageData format
  • Error handling: Uses nock for HTTP mocking and validates error scenarios
  • Configuration validation: Tests zod schema validation for connector config

Test Coverage

  • All core functionality covered by unit tests
  • HTTP request/response cycles mocked with nock
  • Configuration validation tested
  • Error scenarios handled appropriately

Testing

  • Built successfully with docker build -t logto:latest .
  • ran the image using docker-compose and tested e2e

Screenshots

Screenshot 2025-07-03 at 1 27 48 PM Screenshot 2025-07-03 at 1 28 41 PM Screenshot 2025-07-03 at 1 31 36 PM Screenshot 2025-07-03 at 1 37 43 PM Screenshot 2025-07-03 at 1 32 47 PM

Copy link

github-actions bot commented Jul 3, 2025

COMPARE TO master

Total Size Diff ⚠️ 📈 +16.51 KB

Diff by File
Name Diff
.changeset/olive-maps-wave.md 📈 +69 Bytes
packages/connectors/connector-http-sms/README.md 📈 +1.52 KB
packages/connectors/connector-http-sms/logo-dark.svg 📈 +4.09 KB
packages/connectors/connector-http-sms/logo.svg 📈 +4.09 KB
packages/connectors/connector-http-sms/package.json 📈 +1.57 KB
packages/connectors/connector-http-sms/src/constant.ts 📈 +941 Bytes
packages/connectors/connector-http-sms/src/index.test.ts 📈 +1.16 KB
packages/connectors/connector-http-sms/src/index.ts 📈 +1.87 KB
packages/connectors/connector-http-sms/src/mock.ts 📈 +188 Bytes
packages/connectors/connector-http-sms/src/types.ts 📈 +204 Bytes
pnpm-lock.yaml 📈 +859 Bytes

Copy link
Contributor

@wangsijie wangsijie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for the contribution. Could you please check the requirement of the commitlint?

@charIeszhao charIeszhao requested a review from Copilot July 4, 2025 09:58
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new HTTP-based SMS connector mirroring the existing HTTP email connector for sending SMS messages via JSON payloads to configurable endpoints.

  • Defines Zod schema and TypeScript types for connector configuration
  • Implements sendMessage logic with HTTP error handling and optional auth header
  • Adds unit tests, mock data, metadata, documentation, and changelog for initial release

Reviewed Changes

Copilot reviewed 8 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/types.ts Adds httpSmsConfigGuard and HttpSmsConfig
src/mock.ts Provides mockedConfig for testing
src/index.ts Implements connector creation and sendMessage
src/index.test.ts Adds unit tests for happy path
src/constant.ts Defines connector metadata and form items
package.json Declares package info, dependencies, and scripts
README.md Documents setup, payload, and usage
CHANGELOG.md Records initial 1.0.0 release
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (3)

packages/connectors/connector-http-sms/src/index.ts:40

  • The error branch for non-HTTP errors isn’t covered by tests. Add a unit test simulating a network or validation failure to ensure this path is handled correctly.
    } catch (error: unknown) {

packages/connectors/connector-http-sms/README.md:33

  • [nitpick] The link references the passwordless.ts types but this is an SMS connector. Consider linking to the correct SMS template type definitions in the connector-kit for clarity.
You can find all of the types in https://docs.logto.io/docs/recipes/configure-connectors/sms-connector/configure-popular-sms-service/#sms-template, and the full type definition of `SendMessageData` in [connector-kit](https://github.com/logto-io/logto/tree/master/packages/toolkit/connector-kit/src/types/passwordless.ts). 

packages/connectors/connector-http-sms/src/constant.ts:32

  • [nitpick] The tooltip language is slightly unclear. Consider rephrasing to: ‘Optional HTTP Authorization header to include in the request for API authentication.’
        'The authorization header to be sent with the request, you can verify the value in your server.',

@github-actions github-actions bot added size/l and removed size/l labels Jul 4, 2025
@michakfromparis
Copy link
Author

Thanks for the review. I think I addressed all issues. lmk and feel free to take over

@wangsijie
Copy link
Contributor

hi @michakfromparis, one last thing, you need to sign your commits.

michakfromparis and others added 5 commits July 9, 2025 10:21
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@michakfromparis michakfromparis force-pushed the feature/connector-http-sms branch from c2e1da6 to 1348ef6 Compare July 9, 2025 08:22
@github-actions github-actions bot added size/l and removed size/l labels Jul 9, 2025
@michakfromparis
Copy link
Author

Hey @wangsijie! I just signed all my commits and force pushed. Let me know if you need anything else from us.

@wangsijie
Copy link
Contributor

@michakfromparis The pnpm lock file is not up-to-date, can you please run pnpm i and then push the changes? Or you can give us edit permission of this PR.

@github-actions github-actions bot added size/l and removed size/l labels Jul 11, 2025
@michakfromparis
Copy link
Author

@wangsijie I just did!

@wangsijie
Copy link
Contributor

@michakfromparis CI failed, please check the lint issues.

@michakfromparis michakfromparis force-pushed the feature/connector-http-sms branch from 79c7ed3 to 4ea3ea3 Compare July 24, 2025 18:42
@github-actions github-actions bot added size/l and removed size/l labels Jul 24, 2025
@github-actions github-actions bot added size/l and removed size/l labels Jul 24, 2025
@michakfromparis
Copy link
Author

@wangsijie I just got back, rewrote all the commit messages and merged with upstream. I guess (hope) this should fix the issues.

@wangsijie
Copy link
Contributor

@michakfromparis you can enable "Allow edits by maintainers", that would make things easier, I can take care of the rest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

2 participants