|
1 | 1 | <!-- include ../../readme.md#cli --> |
2 | | -<!-- include https://github.com/devlooped/sponsors/raw/main/footer.md --> |
| 2 | +<!-- #cli --> |
| 3 | + |
| 4 | +Provides a command-line interface for the [WhatsApp](https://nuget.org/packages/Devlooped.WhatsApp) |
| 5 | +library and its backend functions. This allows you to interact with your WhatsApp pipeline without |
| 6 | +having to set up your WhatsApp for Business app for local development. |
| 7 | + |
| 8 | +The backend functions are only enabled if the hosting environment is set to `Development` so that |
| 9 | +in production, the CLI endpoint is not available. Example with text format: |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | +Yaml format: |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | +JSON format: |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | +The console will automatically remember the last used WhatsApp endpoint, output format and simulated |
| 22 | +user phone number. |
| 23 | + |
| 24 | +```bash |
| 25 | +Usage: whatsapp [OPTIONS]+ |
| 26 | +Options: |
| 27 | + -u, --url WhatsApp functions endpoint |
| 28 | + -n, --number=VALUE Your WhatsApp user phone number |
| 29 | + -j, --json Format output as JSON |
| 30 | + -t, --text Format output as text |
| 31 | + -y, --yaml Format output as YAML |
| 32 | + -?, -h, --help Display this help. |
| 33 | + -v, --version Render tool version and updates. |
| 34 | +``` |
| 35 | + |
| 36 | +to render the responses since it provides a more readable format than JSON. |
| 37 | + |
| 38 | +For non-text messages, the CLI falls short since you cannot attach files or images. For these |
| 39 | +cases, you can continue to send messages via WhatsApp, but get the responses also in the CLI. |
| 40 | +This works by inspecting messages in the current conversation (so it depends on `UseConversation`) |
| 41 | +and detecting if any messages were sent by the CLI. If that is the case, non-console messages |
| 42 | +will generate responses for the CLI as well: |
| 43 | + |
| 44 | +```csharp |
| 45 | +builder.Services.AddWhatsApp<MyWhatsAppHandler>() |
| 46 | + .UseOpenTelemetry(builder.Environment.ApplicationName) |
| 47 | + .UseConversation() |
| 48 | + .UseConsole() // 👈 Enable CLI support for WhatsApp-originated messages |
| 49 | +
|
| 50 | +``` |
| 51 | + |
| 52 | +> [!IMPORTANT] |
| 53 | +> `UseConsole` will only be added to the pipeline if the hosting environment is set to `Development`, |
| 54 | +> so it's not necessary to check for that in your code. This is to ensure that the CLI behaviors |
| 55 | +> never impact production environments. |
| 56 | +
|
| 57 | +<!-- #cli --> |
| 58 | +<!-- ../../readme.md#cli --> |
| 59 | +<!-- include https://github.com/devlooped/sponsors/raw/main/footer.md --> |
| 60 | +# Sponsors |
| 61 | + |
| 62 | +<!-- sponsors.md --> |
| 63 | +[](https://github.com/clarius) |
| 64 | +[](https://github.com/MFB-Technologies-Inc) |
| 65 | +[](https://github.com/torutek-gh) |
| 66 | +[](https://github.com/drivenet) |
| 67 | +[](https://github.com/Keflon) |
| 68 | +[](https://github.com/tbolon) |
| 69 | +[](https://github.com/kfrancis) |
| 70 | +[](https://github.com/twenzel) |
| 71 | +[](https://github.com/unoplatform) |
| 72 | +[](https://github.com/rbnswartz) |
| 73 | +[](https://github.com/jfoshee) |
| 74 | +[](https://github.com/Mrxx99) |
| 75 | +[](https://github.com/eajhnsn1) |
| 76 | +[](https://github.com/davidjenni) |
| 77 | +[](https://github.com/Jonathan-Hickey) |
| 78 | +[](https://github.com/akunzai) |
| 79 | +[](https://github.com/KenBonny) |
| 80 | +[](https://github.com/SimonCropp) |
| 81 | +[](https://github.com/agileworks-eu) |
| 82 | +[](https://github.com/arsdragonfly) |
| 83 | +[](https://github.com/vezel-dev) |
| 84 | +[](https://github.com/ChilliCream) |
| 85 | +[](https://github.com/4OTC) |
| 86 | +[](https://github.com/v-limo) |
| 87 | +[](https://github.com/jordansjones) |
| 88 | +[](https://github.com/DominicSchell) |
| 89 | +[](https://github.com/jwendl) |
| 90 | +[](https://github.com/adalon) |
| 91 | +[](https://github.com/Eule02) |
| 92 | +[](https://github.com/alexrp) |
| 93 | +[](https://github.com/henkmartijn) |
| 94 | +[](https://github.com/sailro) |
| 95 | +[](https://github.com/torutek) |
| 96 | + |
| 97 | + |
| 98 | +<!-- sponsors.md --> |
| 99 | + |
| 100 | +[](https://github.com/sponsors/devlooped) |
| 101 | + |
| 102 | + |
| 103 | +[Learn more about GitHub Sponsors](https://github.com/sponsors) |
| 104 | + |
| 105 | +<!-- https://github.com/devlooped/sponsors/raw/main/footer.md --> |
0 commit comments