Skip to content

Commit

Permalink
Use flowPath to construct links
Browse files Browse the repository at this point in the history
This method returns a path using the parameterized name
We still want the flow name for display in messages, but need to use
the parameterized name for links
The flowPath returned also includes the organization name, so we can
remove that from the script and config
  • Loading branch information
kb0rg committed Aug 1, 2019
1 parent c14421e commit a648009
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
2 changes: 1 addition & 1 deletion lib/flowdock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,4 @@ class Session {
}
}

export { Session, URLs }
export { Session, URLs, APP_BASE_URL }
38 changes: 18 additions & 20 deletions scripts/suggest.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//
// Configuration:
// SUGGESTION_ALERT_ROOM - name of flow to use for suggestion posts if robot name not found in TARGET_FLOW_PER_ROBOT
// FLOWDOCK_ORGANIZATION_NAME - name of flowdock organization for constructing urls
//
// Commands:
// hubot suggest <your idea here> - Posts a message to the main hubot flow, with content of the suggestion & name of the user, and replies to the command with a link to that flow
Expand All @@ -25,10 +24,6 @@ const {
} = require("../lib/flowdock-util")

module.exports = function(robot) {
const flowdockOrgName = fetchConfigOrReportIssue(
robot,
"FLOWDOCK_ORGANIZATION_NAME",
)
const suggestionAlertRoomName = fetchConfigOrReportIssue(
robot,
"SUGGESTION_ALERT_ROOM",
Expand All @@ -39,14 +34,19 @@ module.exports = function(robot) {
)
let suggestionAlertRoomReference = ""

if (!suggestionAlertRoomName || !flowdockOrgName) {
if (!robot.adapter.flowPath) {
// this is local dev (the config utilities would have thrown if it weren't)
// fall back to a reference to the room name instead of a link
suggestionAlertRoomReference = `${suggestionAlertRoomName || "Shell"}`
} else {
let suggestionAlertRoomLink = flowdock.URLs.flow
.replace(/{orgName}/, flowdockOrgName.toLowerCase())
.replace(/{flowName}/, suggestionAlertRoomName.toLowerCase())
let suggestionAlertRoom = getRoomInfoFromIdOrName(
robot.adapter,
suggestionAlertRoomName,
)
let suggestionAlertRoomLink = `${
flowdock.APP_BASE_URL
}/${robot.adapter.flowPath(suggestionAlertRoom)}`

suggestionAlertRoomReference = `[${suggestionAlertRoomName}](${suggestionAlertRoomLink})`
}

Expand Down Expand Up @@ -77,32 +77,30 @@ module.exports = function(robot) {
return
}

let sourceFlow = getRoomNameFromId(robot.adapter, res.message.room)
let sourceFlowName = getRoomNameFromId(robot.adapter, res.message.room)
let originalThreadReference = ""

if (!sourceFlow || !flowdockOrgName) {
if (!robot.adapter.flowPath) {
// this is probably local dev, but no special handling needed
// let's log an error in case this ever happens in prod
robot.logger.info(
`Could not get room name from res.message.room: ${res.message.room}.`,
)
// and fall back to a reference to the room instead of a link
sourceFlow = res.message.room
sourceFlowName = res.message.room
originalThreadReference = `Refer to original thread in: ${res.message.room}.`
} else {
let sourceThreadId = res.message.metadata.thread_id
let sourceThreadLink = flowdock.URLs.thread
.replace(
/{orgName}/,
process.env["FLOWDOCK_ORGANIZATION_NAME"].toLowerCase(),
)
.replace(/{flowName}/, sourceFlow.toLowerCase())
.replace(/{threadId}/, sourceThreadId)
let sourceFlow = getRoomInfoFromIdOrName(robot.adapter, sourceFlowName)
let sourceThreadPath = `${robot.adapter.flowPath(
sourceFlow,
)}/${sourceThreadId}`
let sourceThreadLink = `${flowdock.APP_BASE_URL}/${sourceThreadPath}`
originalThreadReference = `See [original thread](${sourceThreadLink}).`
}

// post suggestion message & related info
let formattedSuggestion = `@${res.message.user.name} just made a #suggestion in ${sourceFlow}:\n>${userSuggestion}\n\n${originalThreadReference}`
let formattedSuggestion = `@${res.message.user.name} just made a #suggestion in ${sourceFlowName}:\n>${userSuggestion}\n\n${originalThreadReference}`
let envelope = {
room: suggestionAlertRoomId,
}
Expand Down

0 comments on commit a648009

Please sign in to comment.