Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phone number inventory management #1525

Merged
merged 24 commits into from
May 28, 2020
Merged

Phone number inventory management #1525

merged 24 commits into from
May 28, 2020

Conversation

matteosb
Copy link
Collaborator

@matteosb matteosb commented May 1, 2020

First part of #1518.

This adds the phone number inventory table and basic admin functionality to list and buy numbers. It also allows numbers to be added directly to organization-scoped Twilio Messaging Services.

Note: allowing individual campaigns to create messaging services with numbers from the inventory will be added in a later release.

@matteosb matteosb requested a review from schuyler1d May 1, 2020 16:24
@schuyler1d schuyler1d added the S-work in progress (WIP) Status: PR label for work that is not yet ready to be reviewed label May 1, 2020
@matteosb matteosb changed the title Proof of concept: twilio phone number inventory management Phone number inventory management May 6, 2020
Copy link
Collaborator

@schuyler1d schuyler1d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good so far!

@@ -10,6 +10,8 @@ import {
import { log } from "../../../lib";
import { saveNewIncomingMessage } from "./message-sending";
import { getConfig } from "./config";
import _ from "lodash";
import urlJoin from "url-join";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't look like you're using this method or library -- can we delete it after all?

const rows = _.times(limit, () => ({
organization_id: organization.id,
area_code: areaCode,
phone_number: `+1${areaCode}555FAKE`,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't this need to be different for each row? -- I do like the TEXT in the number to make it 'really broken' -- maybe 555FK{random two digits}?
Similar to this code:
https://github.com/MoveOnOrg/Spoke/blob/main/src/integrations/contact-loaders/test-fakedata/index.js#L128-L130

Nit: Aesthetically, we try to avoid using lodash, when a native JS pattern is ok. _.chunk seems like a decent exception. I'm on the edge here -- I think I'd favor a boring for loop, so people don't need to lookup what _.times does.

@@ -91,6 +91,13 @@ export default function renderIndex(html, css, assetMap, store) {
window.EXPERIMENTAL_TAGS=${process.env.EXPERIMENTAL_TAGS || false}
window.EXPERIMENTAL_TEXTERUI="${process.env.EXPERIMENTAL_TEXTERUI || ""}"
window.TWILIO_MULTI_ORG=${process.env.TWILIO_MULTI_ORG || false}
window.EXPERIMENTAL_PHONE_INVENTORY=${getConfig(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one downside of using global window variables for these things is that it can't be per-org, then, because this globally loaded -- it might be better to have an organization graphql property that can return getConfig('EXPERIMENTAL_PHONE_INVENTORY', organization) and then condition on that (after adding to a (apparently not yet present) organization query in the components/AdminDashboard.jsx component

@matteosb matteosb marked this pull request as ready for review May 11, 2020 23:27
@matteosb
Copy link
Collaborator Author

@schuyler1d This is ready for a full review now. Screenshots:

PhoneNumbersForm
Screenshot from 2020-05-11 19-30-06
Screenshot from 2020-05-11 19-34-36

@matteosb matteosb removed the S-work in progress (WIP) Status: PR label for work that is not yet ready to be reviewed label May 12, 2020
@matteosb
Copy link
Collaborator Author

Added functionality to add purchased numbers to organization messaging services from the UI

Screenshot from 2020-05-15 16-53-32

cc @jeffm2001, this should work well with TWILIO_MULTI_ORG

Copy link
Collaborator

@schuyler1d schuyler1d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good -- just a few nits.

*/
async function searchForAvailableNumbers(twilioInstance, areaCode, limit) {
const count = Math.min(limit, 30); // Twilio limit
return twilioInstance.availablePhoneNumbers("US").local.list({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's make this an environment variable getConfig(COUNTRY_CODE, organization) || "US"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I use the PHONE_NUMBER_COUNTRY env var, which appears to be used for formatting, or is there a reason to introduce a new one?

@@ -1298,6 +1299,52 @@ const rootMutations = {
.where("id", id)
.update({ is_deleted: true });
return { id };
},
buyPhoneNumbers: async (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lperson has started what might be a good trend in creating these as mutations/ files rather than continue making the large schema.js file even bigger.

Optional, but if you move it to one, I think that would be good. If you do so, please move the whole function, so you can import and then just include buyPhoneNumbers as a unitary key-value in the list.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, i definitely prefer this pattern

@@ -61,6 +61,7 @@ const tableList = [
"question_response",
"tag",
"tag_campaign_contact",
"owned_phone_number",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's silly, but can you create a models/owned-phone-number.js file in the style of the old ones. even if it's dead code, I'd like us to keep that directory documenting the current schema for all the models (rather than needing to search through changes in the migrations).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. As we plan the final phase of the migration away from thinky we should consider adding a pg schema dump as a reference

if (!areaCode || !limit) {
throw new Error("areaCode and limit are required");
}
const organization = await Organization.get(job.organization_id);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use loaders here, so cache can be used.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cacheableData, not loaders, since we are outside of the request scope right?

@@ -5,6 +5,20 @@ require("dotenv").load();
require("babel-register");
require("babel-polyfill");

if (process.env.DEFAULT_SERVICE !== "fakeservice") {
throw Error(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even so, can we do conditionals on DEFAULT_SERVICE == 'fakeservice' for the number buying parts within the cypress tasks themselves?

@matteosb
Copy link
Collaborator Author

@schuyler1 review comments addressed, mind taking another look?

@schuyler1d schuyler1d added the S-ready for stage-main (qa) Status (ADMINS ONLY): PR label for those ready to be added for stage: Approved, tests, etc label May 20, 2020
@ibrand ibrand merged commit 45e8805 into StateVoicesNational:main May 28, 2020
@matteosb matteosb deleted the inventory-part-1 branch July 9, 2020 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-ready for stage-main (qa) Status (ADMINS ONLY): PR label for those ready to be added for stage: Approved, tests, etc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants