Skip to content

Commit

Permalink
♻️ small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Petter Andersson committed Nov 23, 2022
1 parent eed13c4 commit a57b4a7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ AMQP_URI=amqp://<user>:<password>@localhost:<port>
AMQP_EXCHANGE=gdi-about-me-person-changed
AMQP_QUEUE=sms-queue
AMQP_FILTER=phone.changed
SMS_BASEPATH=https://helsingborg.se/verify
SMS_BASEPATH=https://<domain>/verify?mail=
SMS_PROXY_URL=
SMS_PROXY_KEY=
2 changes: 1 addition & 1 deletion src/services/content-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { MqMessageBody, ContentService } from '../types'
const formatContent = (verificationCode: string, basePath: string): string =>`Hej!
Tack för att du angett ditt telefonnummer på helsingborg.se
För att verifiera att det är ditt nummer, vänligen bekräfta genom
att klicka på denna länk: ${basePath}/${verificationCode}`
att klicka på denna länk: ${basePath}${verificationCode}`

const getContentServiceFromEnv = (): ContentService => getContentService(
getEnv('SMS_BASEPATH')
Expand Down
15 changes: 10 additions & 5 deletions src/services/listener-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,21 @@ const getListenerService = ({ uri, exchange, queue, topic }: ListenerServicePara

debug('Waiting for messages. Ctrl-C to exit...')

await engine.consume(queue, async (message: MqMessageEnvelope) => {
debug(message.content.toString())

handler(JSON.parse(message.content.toString())).then(() => {
await engine.consume(queue, async (message: MqMessageEnvelope) => {
const payload = JSON.parse(message.content.toString())

debug(`${getId(message)} Message RECEIVED, Number: ('${payload.number}')`)

handler(payload).then(() => {
engine.ack(message)
}).catch(() => {
debug(`${getId(message)} Message send SUCCEEDED`)
}).catch((error) => {
engine.nack(message)
debug(`${getId(message)} Message send FAILED with status ('${error.status}')`)
})
})
},
})
const getId = (message: MqMessageEnvelope): string => `${message.fields.deliveryTag}/${Number(message.fields.redelivered)}`

export { getListenerServiceFromEnv, getListenerService }

0 comments on commit a57b4a7

Please sign in to comment.