Skip to content

Commit 4d77db1

Browse files
authored
🎨 improvements (#189)
* πŸ”§ chore: update federated server default config * πŸ› fix: SMS service send payload * 🏷️ chore: add send sms payload type * 🎨 fix: pepper fetching * πŸš€ chore: update docker compose * πŸ§ͺ chore: update SMS service tests
1 parent 8fd581f commit 4d77db1

File tree

6 files changed

+47
-16
lines changed

6 files changed

+47
-16
lines changed

β€Ždocker-compose.yml

+8-1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ services:
8989
- ADDITIONAL_FEATURES=true
9090
- FEDERATED_IDENTITY_SERVICES=fed.docker.localhost
9191
- NODE_TLS_REJECT_UNAUTHORIZED=0
92+
- SMS_API_KEY=SOME_SECRET_KEY
93+
94+
- SMS_API_URL=https://api.octopush.com/v1/public
9295

9396
fed:
9497
build:
@@ -121,8 +124,11 @@ services:
121124
# - UPDATE_FEDERATED_IDENTITY_HASHES_CRON=0-59/2 * * * *
122125
# - UPDATE_USERS_CRON=1-59/2 * * * *
123126
- ADDITIONAL_FEATURES=true
124-
- TRUSTED_SERVERS_ADDRESSES=172.18.0.1/16
127+
- TRUSTED_SERVERS_ADDRESSES=172.18.0.1/16,172.31.0.6,172.31.0.5,172.31.0.1/16
125128
- NODE_TLS_REJECT_UNAUTHORIZED=0
129+
- SMS_API_KEY=SOME_SECRET_KEY
130+
131+
- SMS_API_URL=https://api.octopush.com/v1/public
126132

127133
chat:
128134
image: linagora/twake-web
@@ -151,6 +157,7 @@ services:
151157
- chat
152158
- synapse
153159
- tom
160+
- fed
154161
networks:
155162
frontend:
156163
aliases:

β€Žpackages/federated-identity-service/src/config.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,9 @@
4949
"userdb_user": "",
5050
"template_dir": "./templates",
5151
"trust_x_forwarded_for": false,
52-
"trusted_servers_addresses": []
53-
}
52+
"trusted_servers_addresses": [],
53+
"sms_api_login": "",
54+
"sms_api_key": "",
55+
"sms_api_url": "",
56+
"chat_url": ""
57+
}

β€Žpackages/matrix-identity-server/src/invitation/index.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,16 @@ const StoreInvit = <T extends string = never>(
230230
try {
231231
const authHeader = req.headers.authorization as string
232232
const validToken = authHeader.split(' ')[1]
233-
const _pepper = idServer.db.get('keys', ['data'], {
233+
const papperQuery = (await idServer.db.get('keys', ['data'], {
234234
name: 'pepper'
235-
})
235+
})) as unknown as Record<'data', string>[]
236+
237+
if (!papperQuery || !papperQuery.length) {
238+
send(res, 500, errMsg('unknown', 'No pepper found'))
239+
return
240+
}
241+
242+
const _pepper = papperQuery[0].data
236243

237244
const response = await fetch(
238245
buildUrl(idServer.conf.base_url, '/_matrix/identity/v2/lookup'),

β€Žpackages/matrix-identity-server/src/types.ts

+11
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,14 @@ export interface invitationToken {
121121
address: string
122122
data: ThirPartyInvitePayload
123123
}
124+
125+
export interface SendSmsPayload {
126+
text: string
127+
recipients: Recipient[]
128+
type: 'sms_premium' | 'sms_low_cost'
129+
sender: string
130+
}
131+
132+
interface Recipient {
133+
phone_number: string
134+
}

β€Žpackages/matrix-identity-server/src/utils/sms-service.test.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,10 @@ describe('the SMS service', () => {
6868
'api-key': 'test_key'
6969
},
7070
body: JSON.stringify({
71-
to: '+330744556688',
72-
body: 'test sms',
73-
from: 'Twake Chat'
71+
sender: 'Twake',
72+
recipients: [{ phone_number: '+330744556688' }],
73+
text: 'test sms',
74+
type: 'sms_low_cost'
7475
})
7576
}
7677
)

β€Žpackages/matrix-identity-server/src/utils/sms-service.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { TwakeLogger } from '@twake/logger'
2-
import { Config, ISMSService } from '../types'
2+
import { Config, ISMSService, SendSmsPayload } from '../types'
33
import { buildUrl } from '../utils'
44

55
export class SmsService implements ISMSService {
@@ -29,19 +29,20 @@ export class SmsService implements ISMSService {
2929
/**
3030
* sends an sms to the given number
3131
*
32-
* @param to - the number to send the sms to
33-
* @param body - the body of the sms to send
32+
* @param {string} to - the number to send the sms to
33+
* @param {string} text - the body of the sms to send
3434
*/
35-
async send(to: string, body: string): Promise<void> {
35+
async send(to: string, text: string): Promise<void> {
3636
try {
3737
const response = await fetch(this.API_ENDPOINT, {
3838
method: 'POST',
3939
headers: this.HEADERS,
4040
body: JSON.stringify({
41-
to,
42-
body,
43-
from: this.sender
44-
})
41+
sender: 'Twake',
42+
recipients: [{ phone_number: to }],
43+
text,
44+
type: 'sms_low_cost'
45+
} satisfies SendSmsPayload)
4546
})
4647

4748
const responseBody = await response.json()

0 commit comments

Comments
Β (0)