|
| 1 | +# zio-messaging-entrance-group |
| 2 | + |
| 3 | +Entrance Group SMS integration for ZIO applications. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +This module provides two implementations for sending SMS messages through Entrance Group: |
| 8 | + |
| 9 | +1. **Hook Campaign** (`EntranceGroupHookCampaignSmsService`): Uses an existing campaign via webhook |
| 10 | +2. **Manual Campaign** (`EntranceGroupCreateManualCampaignSmsService`): Creates new campaigns per message |
| 11 | + |
| 12 | +## Installation |
| 13 | + |
| 14 | +Add to your `build.sbt`: |
| 15 | + |
| 16 | +```scala |
| 17 | +libraryDependencies += "io.github.nafg.zio-messaging" %% "zio-messaging-entrance-group" % "<version>" |
| 18 | +``` |
| 19 | + |
| 20 | +For Bleep (`bleep.yaml`): |
| 21 | + |
| 22 | +```yaml |
| 23 | +dependencies: |
| 24 | + - io.github.nafg.zio-messaging::zio-messaging-entrance-group:<version> |
| 25 | +``` |
| 26 | +
|
| 27 | +## Usage |
| 28 | +
|
| 29 | +### Hook Campaign Example |
| 30 | +
|
| 31 | +Use this when you have an existing campaign and want to send messages via its webhook: |
| 32 | +
|
| 33 | +```scala |
| 34 | +import io.github.nafg.messaging.SmsService |
| 35 | +import io.github.nafg.messaging.entrancegrp.EntranceGroupHookCampaignSmsService |
| 36 | +import io.github.nafg.scalaphonenumber.PhoneNumber |
| 37 | +import zio._ |
| 38 | +import zio.http.Client |
| 39 | + |
| 40 | +val entranceGroupLayer = ZLayer.succeed( |
| 41 | + EntranceGroupHookCampaignSmsService.Config( |
| 42 | + campaignId = 12345L, |
| 43 | + authKey = Config.Secret("X-API-Key"), |
| 44 | + authValue = Config.Secret("your-api-key") |
| 45 | + ) |
| 46 | +) ++ Client.default >>> EntranceGroupHookCampaignSmsService.layer |
| 47 | + |
| 48 | +val program = for { |
| 49 | + sms <- ZIO.service[SmsService] |
| 50 | + recipient = PhoneNumber.parseInternational("+15559876543").get |
| 51 | + _ <- sms.sendMessage(Seq(recipient), "Hello from Entrance Group!") |
| 52 | +} yield () |
| 53 | + |
| 54 | +program.provide(entranceGroupLayer) |
| 55 | +``` |
| 56 | + |
| 57 | +### Manual Campaign Example |
| 58 | + |
| 59 | +Use this when you want to create a new campaign for each batch of messages: |
| 60 | + |
| 61 | +```scala |
| 62 | +import io.github.nafg.messaging.SmsService |
| 63 | +import io.github.nafg.messaging.entrancegrp.EntranceGroupCreateManualCampaignSmsService |
| 64 | +import io.github.nafg.scalaphonenumber.PhoneNumber |
| 65 | +import zio._ |
| 66 | +import zio.http.Client |
| 67 | + |
| 68 | +val entranceGroupLayer = ZLayer.succeed( |
| 69 | + EntranceGroupCreateManualCampaignSmsService.Config( |
| 70 | + campaignName = "My Campaign", |
| 71 | + authKey = Config.Secret("X-API-Key"), |
| 72 | + authValue = Config.Secret("your-api-key") |
| 73 | + ) |
| 74 | +) ++ Client.default >>> EntranceGroupCreateManualCampaignSmsService.layer |
| 75 | + |
| 76 | +val program = for { |
| 77 | + sms <- ZIO.service[SmsService] |
| 78 | + recipients = Seq( |
| 79 | + PhoneNumber.parseInternational("+15551111111").get, |
| 80 | + PhoneNumber.parseInternational("+15552222222").get |
| 81 | + ) |
| 82 | + _ <- sms.sendMessage(recipients, "Broadcast message!") |
| 83 | +} yield () |
| 84 | + |
| 85 | +program.provide(entranceGroupLayer) |
| 86 | +``` |
| 87 | + |
| 88 | +## Configuration |
| 89 | + |
| 90 | +### EntranceGroupHookCampaignSmsService.Config |
| 91 | + |
| 92 | +- `campaignId: Long` - The ID of the existing campaign |
| 93 | +- `authKey: Config.Secret` - The authentication header key (e.g., "X-API-Key") |
| 94 | +- `authValue: Config.Secret` - The authentication header value (your API key) |
| 95 | + |
| 96 | +### EntranceGroupCreateManualCampaignSmsService.Config |
| 97 | + |
| 98 | +- `campaignName: String` - The name for the campaigns that will be created |
| 99 | +- `authKey: Config.Secret` - The authentication header key (e.g., "X-API-Key") |
| 100 | +- `authValue: Config.Secret` - The authentication header value (your API key) |
| 101 | + |
| 102 | +## API Endpoints |
| 103 | + |
| 104 | +This module uses two Entrance Group API endpoints: |
| 105 | + |
| 106 | +- **Hook Campaign**: `POST https://entrancegrp.com/api/hooks/campaigns/{id}` |
| 107 | +- **Manual Campaign**: `POST https://apiv2.entrancegrp.com/campaigns` |
| 108 | + |
| 109 | +All endpoints are defined in `EntranceGroupApi` using zio-http's type-safe endpoint DSL. |
| 110 | + |
| 111 | +## Dependencies |
| 112 | + |
| 113 | +- `zio-messaging` (core module) |
| 114 | +- `zio-http` for HTTP client and endpoint definitions |
| 115 | +- `scala-phonenumber` for phone number handling |
| 116 | + |
| 117 | +## License |
| 118 | + |
| 119 | +Licensed under the Apache License, Version 2.0. See the main [LICENSE](../LICENSE) file for details. |
0 commit comments