Skip to content
Snippets Groups Projects
Verified Commit b9886fe6 authored by aguestuser's avatar aguestuser
Browse files

[131][WIP] deconfuse messages

TODO: translations, testing!
parent f00daa36
No related branches found
No related tags found
No related merge requests found
...@@ -18,13 +18,13 @@ const { ...@@ -18,13 +18,13 @@ const {
const messageTypes = { const messageTypes = {
BROADCAST_MESSAGE: 'BROADCAST_MESSAGE', BROADCAST_MESSAGE: 'BROADCAST_MESSAGE',
BROADCAST_RESPONSE: 'BROADCAST_RESPONSE', HOTLINE_MESSAGE: 'HOTLINE_MESSAGE',
COMMAND_RESULT: 'COMMAND_RESULT', COMMAND_RESULT: 'COMMAND_RESULT',
NEW_ADMIN_WELCOME: 'NEW_ADMIN_WELCOME', NEW_ADMIN_WELCOME: 'NEW_ADMIN_WELCOME',
SIGNUP_MESSAGE: 'SIGNUP_MESSAGE', SIGNUP_MESSAGE: 'SIGNUP_MESSAGE',
} }
const { BROADCAST_MESSAGE, BROADCAST_RESPONSE, COMMAND_RESULT, SIGNUP_MESSAGE } = messageTypes const { BROADCAST_MESSAGE, HOTLINE_MESSAGE, COMMAND_RESULT, SIGNUP_MESSAGE } = messageTypes
const { ADMIN } = memberTypes const { ADMIN } = memberTypes
...@@ -38,8 +38,8 @@ const dispatch = async ({ commandResult, dispatchable }) => { ...@@ -38,8 +38,8 @@ const dispatch = async ({ commandResult, dispatchable }) => {
switch (messageType) { switch (messageType) {
case BROADCAST_MESSAGE: case BROADCAST_MESSAGE:
return broadcast(dispatchable) return broadcast(dispatchable)
case BROADCAST_RESPONSE: case HOTLINE_MESSAGE:
return handleBroadcastResponse(dispatchable) return handleHotlineMessage(dispatchable)
case COMMAND_RESULT: case COMMAND_RESULT:
return handleCommandResult({ commandResult, dispatchable }) return handleCommandResult({ commandResult, dispatchable })
case SIGNUP_MESSAGE: case SIGNUP_MESSAGE:
...@@ -54,7 +54,7 @@ const parseMessageType = (commandResult, { sender, channel }) => { ...@@ -54,7 +54,7 @@ const parseMessageType = (commandResult, { sender, channel }) => {
if (commandResult.status === statuses.NOOP) { if (commandResult.status === statuses.NOOP) {
if (sender.type === ADMIN) return BROADCAST_MESSAGE if (sender.type === ADMIN) return BROADCAST_MESSAGE
if (channel.phoneNumber === signupPhoneNumber) return SIGNUP_MESSAGE if (channel.phoneNumber === signupPhoneNumber) return SIGNUP_MESSAGE
return BROADCAST_RESPONSE return HOTLINE_MESSAGE
} }
return COMMAND_RESULT return COMMAND_RESULT
} }
...@@ -78,20 +78,17 @@ const handleSignupMessage = async ({ sock, channel, sender, sdMessage }) => { ...@@ -78,20 +78,17 @@ const handleSignupMessage = async ({ sock, channel, sender, sdMessage }) => {
}) })
} }
const handleBroadcastResponse = dispatchable => { const handleHotlineMessage = dispatchable => {
const { const {
channel: { responsesEnabled }, channel: { responsesEnabled },
sender: { language }, sender: { language, type },
} = dispatchable } = dispatchable
const disabledMessage = messagesIn(language).notifications.hotlineMessagesDisabled(
if (!responsesEnabled) { type === memberTypes.SUBSCRIBER,
return respond({ )
...dispatchable, return responsesEnabled
message: messagesIn(language).notifications.unauthorized, ? relayBroadcastResponse(dispatchable)
status: statuses.UNAUTHORIZED, : respond({ ...dispatchable, status: statuses.UNAUTHORIZED, message: disabledMessage })
})
}
return relayBroadcastResponse(dispatchable)
} }
const handleCommandResult = async ({ commandResult, dispatchable }) => { const handleCommandResult = async ({ commandResult, dispatchable }) => {
...@@ -145,7 +142,7 @@ const relayBroadcastResponse = async ({ db, sock, channel, sender, sdMessage }) ...@@ -145,7 +142,7 @@ const relayBroadcastResponse = async ({ db, sock, channel, sender, sdMessage })
const { language } = sender const { language } = sender
const recipients = channelRepository.getAdminPhoneNumbers(channel) const recipients = channelRepository.getAdminPhoneNumbers(channel)
const notification = messagesIn(language).notifications.broadcastResponseSent(channel) const notification = messagesIn(language).notifications.broadcastResponseSent(channel)
const outMessage = format({ channel, sdMessage, messageType: BROADCAST_RESPONSE, language }) const outMessage = format({ channel, sdMessage, messageType: HOTLINE_MESSAGE, language })
return signal return signal
.broadcastMessage(sock, recipients, outMessage) .broadcastMessage(sock, recipients, outMessage)
.then(() => countBroacast({ db, channel })) .then(() => countBroacast({ db, channel }))
...@@ -184,7 +181,7 @@ const resolvePrefix = (channel, messageType, command, language) => { ...@@ -184,7 +181,7 @@ const resolvePrefix = (channel, messageType, command, language) => {
// INFO & HELP messages provide their own prefixes // INFO & HELP messages provide their own prefixes
return '' return ''
} }
if (messageType === BROADCAST_RESPONSE) { if (messageType === HOTLINE_MESSAGE) {
// subscriber responses get a special header so they don't look like broadcast messages from admins // subscriber responses get a special header so they don't look like broadcast messages from admins
// we clone message to preserve attachments // we clone message to preserve attachments
return `[${prefixes.broadcastResponse}]\n` return `[${prefixes.broadcastResponse}]\n`
......
...@@ -5,9 +5,10 @@ const { ...@@ -5,9 +5,10 @@ const {
} = require('../../../../db/repositories/channel') } = require('../../../../db/repositories/channel')
const systemName = 'the signalboost system administrator' const systemName = 'the signalboost system administrator'
const unauthorized = 'Whoops! You are not authorized to do that on this channel.' const unauthorized =
'Your message could not be processed because you are not subscribed to this channel. Send HELLO to subscribe.'
const invalidNumber = phoneNumber => const invalidNumber = phoneNumber =>
`Whoops! "${phoneNumber}" is not a valid phone number. Phone numbers must include country codes prefixed by a '+'.` `"${phoneNumber}" is not a valid phone number. Phone numbers must include country codes prefixed by a '+'.`
const support = `---------------------------- const support = `----------------------------
HOW IT WORKS HOW IT WORKS
...@@ -36,9 +37,11 @@ const notifications = { ...@@ -36,9 +37,11 @@ const notifications = {
adminAdded: (commandIssuer, addedAdmin) => `New Admin ${addedAdmin} added by ${commandIssuer}`, adminAdded: (commandIssuer, addedAdmin) => `New Admin ${addedAdmin} added by ${commandIssuer}`,
broadcastResponseSent: channel => broadcastResponseSent: channel =>
`Your message was forwarded to the admins of [${channel.name}]. `Your message was anonymously forwarded to the admins of [${
channel.name
}]. Please include your phone number if you want admins to respond to you.
Send HELP to see commands I understand! :)`, You can also send HELP to list valid commands.`,
deauthorization: adminPhoneNumber => ` deauthorization: adminPhoneNumber => `
${adminPhoneNumber} has been removed from this channel because their safety number changed. ${adminPhoneNumber} has been removed from this channel because their safety number changed.
...@@ -55,6 +58,11 @@ Until then, they will be unable to send messages to or read messages from this c ...@@ -55,6 +58,11 @@ Until then, they will be unable to send messages to or read messages from this c
noop: "Whoops! That's not a command!", noop: "Whoops! That's not a command!",
unauthorized: "Whoops! I don't understand that.\n Send HELP to see commands I understand!", unauthorized: "Whoops! I don't understand that.\n Send HELP to see commands I understand!",
hotlineMessagesDisabled: isSubscriber =>
isSubscriber
? 'Sorry, incoming messages are not enabled on this channel. Send HELP to list valid commands.'
: 'Sorry, incoming messages are not enabled on this channel. Send HELLO to subscribe.',
welcome: (addingAdmin, channelPhoneNumber) => ` welcome: (addingAdmin, channelPhoneNumber) => `
You were just made an admin of this Signalboost channel by ${addingAdmin}. Welcome! You were just made an admin of this Signalboost channel by ${addingAdmin}. Welcome!
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment