Skip to content

Modular logistics and supply chain operating system (LSOS)

Update SMS provider configuration UI

Ronald A. Richardson4cd57fd23be8
diff --git a/console/app/components/configure/services.hbs b/console/app/components/configure/services.hbs
index 99090f7d..e7ad4cb4 100644
--- a/console/app/components/configure/services.hbs
+++ b/console/app/components/configure/services.hbs
@@ -46,13 +46,11 @@
<InputGroup @name="Vonage API Key" @value={{this.selectedSmsProviderConfig.api_key}} {{on "input" (fn this.updateSmsProviderField "vonage" "api_key")}} disabled={{this.isLoading}} />
<InputGroup @name="Vonage API Secret" @value={{this.selectedSmsProviderConfig.api_secret}} {{on "input" (fn this.updateSmsProviderField "vonage" "api_secret")}} disabled={{this.isLoading}} />
<InputGroup @name="Vonage From" @value={{this.selectedSmsProviderConfig.from}} {{on "input" (fn this.updateSmsProviderField "vonage" "from")}} disabled={{this.isLoading}} />
- <InputGroup @name="Vonage Base URL" @value={{this.selectedSmsProviderConfig.base_url}} {{on "input" (fn this.updateSmsProviderField "vonage" "base_url")}} disabled={{this.isLoading}} />
{{/if}}
{{#if (eq this.smsSelectedProvider "messagebird")}}
<InputGroup @name="MessageBird Access Key" @value={{this.selectedSmsProviderConfig.access_key}} {{on "input" (fn this.updateSmsProviderField "messagebird" "access_key")}} disabled={{this.isLoading}} />
<InputGroup @name="MessageBird Originator" @value={{this.selectedSmsProviderConfig.originator}} {{on "input" (fn this.updateSmsProviderField "messagebird" "originator")}} disabled={{this.isLoading}} />
- <InputGroup @name="MessageBird Base URL" @value={{this.selectedSmsProviderConfig.base_url}} {{on "input" (fn this.updateSmsProviderField "messagebird" "base_url")}} disabled={{this.isLoading}} />
{{/if}}
{{#if (eq this.smsSelectedProvider "aws_sns")}}
@@ -77,14 +75,25 @@
{{/if}}
{{#if (eq this.smsSelectedProvider "custom_http")}}
+ <div>
+ <label class="form-label">Method</label>
+ <select class="form-select form-select-sm w-full" data-test-custom-http-method {{on "change" (fn this.updateSmsProviderField "custom_http" "method")}}>
+ <option value="POST" selected={{eq (or this.selectedSmsProviderConfig.method "POST") "POST"}}>POST</option>
+ <option value="GET" selected={{eq this.selectedSmsProviderConfig.method "GET"}}>GET</option>
+ </select>
+ </div>
<InputGroup @name="Gateway URL" @value={{this.selectedSmsProviderConfig.url}} {{on "input" (fn this.updateSmsProviderField "custom_http" "url")}} disabled={{this.isLoading}} />
<InputGroup @name="From" @value={{this.selectedSmsProviderConfig.from}} {{on "input" (fn this.updateSmsProviderField "custom_http" "from")}} disabled={{this.isLoading}} />
<InputGroup @name="Auth Header" @value={{this.selectedSmsProviderConfig.auth_header}} {{on "input" (fn this.updateSmsProviderField "custom_http" "auth_header")}} disabled={{this.isLoading}} />
<InputGroup @name="Auth Token" @value={{this.selectedSmsProviderConfig.auth_token}} {{on "input" (fn this.updateSmsProviderField "custom_http" "auth_token")}} disabled={{this.isLoading}} />
<label class="form-label">Headers JSON</label>
<textarea class="form-input w-full font-mono text-xs" rows="4" value={{this.customHttpHeadersText}} {{on "input" (fn this.updateSmsProviderJsonField "custom_http" "headers")}}></textarea>
- <label class="form-label mt-3">Body Template JSON</label>
- <textarea class="form-input w-full font-mono text-xs" rows="5" value={{this.customHttpBodyText}} {{on "input" (fn this.updateSmsProviderJsonField "custom_http" "body")}}></textarea>
+ <label class="form-label mt-3">Query Params JSON</label>
+ <textarea class="form-input w-full font-mono text-xs" rows="4" value={{this.customHttpQueryParamsText}} {{on "input" (fn this.updateSmsProviderJsonField "custom_http" "query_params")}} data-test-custom-http-query-params></textarea>
+ {{#if this.isCustomHttpPostMethod}}
+ <label class="form-label mt-3">Body Template JSON</label>
+ <textarea class="form-input w-full font-mono text-xs" rows="5" value={{this.customHttpBodyText}} {{on "input" (fn this.updateSmsProviderJsonField "custom_http" "body")}} data-test-custom-http-body></textarea>
+ {{/if}}
{{/if}}
</div>
diff --git a/console/app/components/configure/services.js b/console/app/components/configure/services.js
index 8383b36a..073bfbf9 100644
--- a/console/app/components/configure/services.js
+++ b/console/app/components/configure/services.js
@@ -35,6 +35,7 @@ export default class ConfigureServicesComponent extends Component {
@tracked smsTestMessage = 'This is a Fleetbase SMS test.';
@tracked smsTestResponse;
@tracked customHttpHeadersText = '{}';
+ @tracked customHttpQueryParamsText = '{}';
@tracked customHttpBodyText = '{}';
/** sentry service */
@@ -109,6 +110,10 @@ export default class ConfigureServicesComponent extends Component {
this.customHttpHeadersText = event.target.value;
}
+ if (field === 'query_params') {
+ this.customHttpQueryParamsText = event.target.value;
+ }
+
if (field === 'body') {
this.customHttpBodyText = event.target.value;
}
@@ -142,6 +147,10 @@ export default class ConfigureServicesComponent extends Component {
return this.normalizedSms.providers[this.smsSelectedProvider] || {};
}
+ get isCustomHttpPostMethod() {
+ return (this.selectedSmsProviderConfig.method || 'POST').toUpperCase() === 'POST';
+ }
+
get smsConfigForSave() {
const sms = this.normalizedSms;
@@ -256,7 +265,9 @@ export default class ConfigureServicesComponent extends Component {
aws_sns: {},
smpp: {},
custom_http: {
+ method: 'POST',
headers: {},
+ query_params: {},
body: {
to: '{{to}}',
text: '{{text}}',
@@ -307,6 +318,7 @@ export default class ConfigureServicesComponent extends Component {
syncSmsJsonText() {
const customHttpConfig = this.normalizedSms.providers.custom_http || {};
this.customHttpHeadersText = JSON.stringify(customHttpConfig.headers || {}, null, 2);
+ this.customHttpQueryParamsText = JSON.stringify(customHttpConfig.query_params || {}, null, 2);
this.customHttpBodyText = JSON.stringify(
customHttpConfig.body || {
to: '{{to}}',
diff --git a/console/tests/integration/components/configure/services-test.js b/console/tests/integration/components/configure/services-test.js
index 51226918..75806b7e 100644
--- a/console/tests/integration/components/configure/services-test.js
+++ b/console/tests/integration/components/configure/services-test.js
@@ -32,6 +32,21 @@ class FetchStub extends Service {
originator: 'Fleetbase',
base_url: 'https://rest.messagebird.com/messages',
},
+ custom_http: {
+ method: 'POST',
+ url: 'https://sms-gateway.test/send',
+ from: 'Fleetbase',
+ auth_header: 'Authorization',
+ auth_token: 'Bearer token',
+ headers: {
+ 'X-Tenant': 'fleetbase',
+ },
+ query_params: {},
+ body: {
+ recipient: '{{to}}',
+ message: '{{text}}',
+ },
+ },
},
},
};
@@ -92,4 +107,47 @@ module('Integration | Component | configure/services', function (hooks) {
},
});
});
+
+ test('it configures custom http get query params', async function (assert) {
+ await render(hbs`<Configure::Services />`);
+ await waitFor('[data-test-sms-default-provider]');
+
+ assert.dom(this.element).doesNotIncludeText('Vonage Base URL');
+ assert.dom(this.element).doesNotIncludeText('MessageBird Base URL');
+
+ await select('[data-test-sms-default-provider]', 'custom_http');
+ assert.dom('[data-test-sms-configure-provider]').hasValue('custom_http');
+ assert.dom('[data-test-custom-http-body]').exists();
+
+ await select('[data-test-custom-http-method]', 'GET');
+ assert.dom('[data-test-custom-http-body]').doesNotExist();
+
+ await fillIn('[data-test-custom-http-query-params]', '{ "recipient": "{{to}}", "message": "{{text}}", "reference": "{{unique_id}}" }');
+ await fillIn('[data-test-sms-test-phone]', '+15551234567');
+ await click('[data-test-sms-test-button]');
+
+ const fetch = this.owner.lookup('service:fetch');
+
+ assert.strictEqual(fetch.lastPost.url, 'settings/test-sms-provider-config');
+ assert.strictEqual(fetch.lastPost.payload.provider, 'custom_http');
+ assert.deepEqual(fetch.lastPost.payload.config, {
+ method: 'GET',
+ url: 'https://sms-gateway.test/send',
+ from: 'Fleetbase',
+ auth_header: 'Authorization',
+ auth_token: 'Bearer token',
+ headers: {
+ 'X-Tenant': 'fleetbase',
+ },
+ query_params: {
+ recipient: '{{to}}',
+ message: '{{text}}',
+ reference: '{{unique_id}}',
+ },
+ body: {
+ recipient: '{{to}}',
+ message: '{{text}}',
+ },
+ });
+ });
});
diff --git a/packages/core-api b/packages/core-api
index e7ac7053..abd02ef0 160000
--- a/packages/core-api
+++ b/packages/core-api
@@ -1 +1 @@
-Subproject commit e7ac7053f4ddcd7845b329ee019541aeda74b9ff
+Subproject commit abd02ef08f46c5959291941033873f56520b2633