Verified Commit ee5c0461 authored by aguestuser's avatar aguestuser
Browse files

[ns] tweak welcome message / help response

* list phone number in welcome message
* specify subscribe/unsubscribe messages in welcome message & HELP response
parent 1b3fe467
......@@ -36,10 +36,12 @@ ADD ${publisherPhoneNumber}
Until then, they will be unable to send messages to or read messages from this channel.`,
noop: "Whoops! That's not a command!",
unauthorized: "Whoops! I don't understand that.\n Send HELP to see commands I understand!",
welcome: addingPublisher => `
You were just made an admin of this signalboost channel by ${addingPublisher}. Welcome!
welcome: (addingPublisher, channelPhoneNumber) => `
You were just made an admin of this Signalboost channel by ${addingPublisher}. Welcome!
Reply with HELP for more information or GOODBYE to leave.`,
People can subscribe to this channel by sending HELLO to ${channelPhoneNumber} and unsubscribe by sending GOODBYE.
Reply with HELP for more info.`,
signupRequestReceived: (senderNumber, requestMsg) =>
`Signup request received from ${senderNumber}:\n ${requestMsg}`,
signupRequestResponse:
......@@ -66,6 +68,12 @@ const commandResponses = {
// HELP
help: {
publisher: `
HELLO / HOLA
-> subscribes to this channel
GOODBYE / ADIOS
-> unsubscribes from this channel
HELP / AYUDA
-> lists commands
......@@ -82,10 +90,7 @@ ADD +1-555-555-5555
-> makes +1-555-555-5555 an admin
REMOVE +1-555-555-5555
-> removes +1-555-555-5555 as an admin
GOODBYE / ADIOS
-> removes you from channel`,
-> removes +1-555-555-5555 as an admin`,
subscriber: `
HELP / AYUDA
-> lists commands
......
......@@ -120,7 +120,10 @@ const handleNotifications = async ({ commandResult, dispatchable }) => {
// welcome new publisher
await notify({
...notifyBase,
notification: messagesIn(sender.language).notifications.welcome(sender.phoneNumber),
notification: messagesIn(sender.language).notifications.welcome(
sender.phoneNumber,
channel.phoneNumber,
),
recipients: [payload],
})
return notify({
......
......@@ -96,7 +96,10 @@ const updateSafetyNumber = async (db, sock, inboundMsg) => {
)
if (recipient.type === memberTypes.NONE) return Promise.resolve()
if (recipient.type === memberTypes.PUBLISHER && !isWelcomeMessage(sdMessage)) {
if (
recipient.type === memberTypes.PUBLISHER &&
!isWelcomeMessage(sdMessage, channelPhoneNumber)
) {
// If it's a welcome message, someone just re-authorized this recipient, we want to re-trust their keys
return safetyNumberService
.deauthorize(db, sock, channelPhoneNumber, memberPhoneNumber)
......@@ -140,7 +143,7 @@ const classifyPhoneNumber = async (db, channelPhoneNumber, senderPhoneNumber) =>
return { phoneNumber: senderPhoneNumber, type, language }
}
const isWelcomeMessage = sdMessage => {
const isWelcomeMessage = (sdMessage, channelPhoneNumber) => {
const phoneNumberPattern = /\+\d{9,15}/
const headerPattern = /\[.*]\n\n/
const strippedMessage = sdMessage.messageBody
......@@ -152,8 +155,9 @@ const isWelcomeMessage = sdMessage => {
// properly localize this, by including more languages in the input array here!
[messagesIn(defaultLanguage)].find(
messages =>
strippedMessage === messages.notifications.welcome('').trim() || //if added by another admin
strippedMessage === messages.notifications.welcome(messages.systemName).trim(), //if added by sysadmin
strippedMessage === messages.notifications.welcome('', channelPhoneNumber).trim() || //if added by another admin
strippedMessage ===
messages.notifications.welcome(messages.systemName, channelPhoneNumber).trim(), //if added by sysadmin
),
)
}
......
......@@ -13,9 +13,8 @@ const {
signal: { welcomeDelay },
} = require('../../config')
const welcomeNotification = messagesIn(defaultLanguage).notifications.welcome(
messagesIn(defaultLanguage).systemName,
)
const systemName = messagesIn(defaultLanguage).systemName
const welcomeNotification = messagesIn(defaultLanguage).notifications.welcome
// ({ Database, Socket, string, string }) -> Promise<SignalboostStatus>
const addPublisher = async ({ db, sock, channelPhoneNumber, publisherPhoneNumber }) => {
......@@ -25,7 +24,7 @@ const addPublisher = async ({ db, sock, channelPhoneNumber, publisherPhoneNumber
db,
sock,
channel,
notification: welcomeNotification,
notification: welcomeNotification(systemName, channelPhoneNumber),
recipients: [publisherPhoneNumber],
})
return {
......@@ -45,7 +44,7 @@ const create = async ({ db, sock, phoneNumber, name, publishers }) => {
db,
sock,
channel,
notification: welcomeNotification,
notification: welcomeNotification(systemName, channel.phoneNumber),
recipients: channel.publications.map(p => p.publisherPhoneNumber),
})
return { status: pNumStatuses.ACTIVE, phoneNumber, name, publishers }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment