diff --git a/docs/REFERENCE_TEXTER_ACTIVITY_QUERIES.md b/docs/REFERENCE_TEXTER_ACTIVITY_QUERIES.md
index e6a928499..9f6c45714 100644
--- a/docs/REFERENCE_TEXTER_ACTIVITY_QUERIES.md
+++ b/docs/REFERENCE_TEXTER_ACTIVITY_QUERIES.md
@@ -144,8 +144,6 @@ WHERE campaign_id >= 0
ORDER BY 1,2
```
-#### TO DO (wish list) of some useful SQL query examples, for creating redash dashboard reports:
-
- all responses to Initial text, excluding opt-outs, and separate out JSON data from `custom_fields`
```sql
@@ -165,6 +163,573 @@ AND c.id IN (23,25,28,29,30,31,32)
ORDER BY updated_at DESC;
```
-- survey question response counts and percentage of total responses to survey question
+- Messages by Organization, Date, Campaign, or Users
+
+``` sql
+SELECT count(*)
+FROM message m
+left join public."user" u
+on u.id = m.user_id
+left join campaign_contact n
+on m.campaign_contact_id = n.id
+left join campaign c
+on n.campaign_id = c.ID
+left join organization o
+on o.ID = c.organization_ID
+
+-- PLUG IN YOUR DATES, ORGANIZATION NAME, CAMPAIGNS, AND /OR USERS BELOW
+where m.created_at =
+and o.name=
+and c.title=
+and CONCAT(u.first_name, ' ', u.last_name)=
+
+```
+
+- Phone Numbers Texted
+
+``` sql
+select count(distinct m.contact_number) from message m
+left join public."user" u
+on u.id = m.user_id
+left join campaign_contact n
+on m.campaign_contact_id = n.id
+left join campaign c
+on n.campaign_id = c.ID
+left join organization o
+on o.ID = c.organization_ID
+
+-- PLUG IN YOUR DATES, ORGANIZATION NAME, CAMPAIGNS, AND /OR USERS BELOW
+where m.created_at =
+and o.name=
+and c.title=
+and CONCAT(u.first_name, ' ', u.last_name)=
+```
+
+- Outbound Messages
+
+```sql
+
+select count(*) from message m
+left join public."user" u
+on u.id = m.user_id
+left join campaign_contact n
+on m.campaign_contact_id = n.id
+left join campaign c
+on n.campaign_id = c.ID
+left join organization o
+on o.ID = c.organization_ID
+
+-- PLUG IN YOUR DATES, ORGANIZATION NAME, CAMPAIGNS, AND /OR USERS BELOW
+where m.created_at =
+and o.name=
+and c.title=
+and CONCAT(u.first_name, ' ', u.last_name)=
+```
+
+- Inbound Messages
+
+```sql
+select count(*) from message m
+left join public."user" u
+on u.id = m.user_id
+left join campaign_contact n
+on m.campaign_contact_id = n.id
+left join campaign c
+on n.campaign_id = c.ID
+left join organization o
+on o.ID = c.organization_ID
+-- PLUG IN YOUR DATES, ORGANIZATION NAME, CAMPAIGNS, AND /OR USERS BELOW
+where m.created_at =
+and o.name=
+and c.title=
+and CONCAT(u.first_name, ' ', u.last_name)=
+```
+- Texters
+
+```sql
+SELECT count(distinct m.user_id) from message m
+left join public."user" u
+on u.id = m.user_id
+left join campaign_contact n
+on m.campaign_contact_id = n.id
+left join campaign c
+on n.campaign_id = c.ID
+left join organization o
+on o.ID = c.organization_ID
+-- PLUG IN YOUR DATES, ORGANIZATION NAME, CAMPAIGNS, AND /OR USERS BELOW
+where m.created_at =
+and o.name=
+and c.title=
+and CONCAT(u.first_name, ' ', u.last_name)=
+```
+
+- Inbound vs Outbound, Pie Graph
+
+```sql
+select case when m.is_from_contact = true then 'Inbound' else 'Outbound' end as MessageType, count(*) from message m
+left join public."user" u
+on u.id = m.user_id
+left join campaign_contact n
+on m.campaign_contact_id = n.id
+left join campaign c
+on n.campaign_id = c.ID
+left join organization o
+on o.ID = c.organization_ID
+
+-- PLUG IN YOUR DATES, ORGANIZATION NAME, CAMPAIGNS, AND /OR USERS BELOW
+where m.created_at =
+and o.name=
+and c.title=
+and CONCAT(u.first_name, ' ', u.last_name)=
+-- PLUG IN DETAILS ABOVE, OR DO NOT INCLUDE AT ALL
+
+group by MessageType
+```
+- Message Status
+
+```sql
+select n.message_status, count(*)
+from campaign_contact n
+left join campaign c
+on c.id = n.campaign_id
+left join organization o
+on o.ID = c.organization_ID
+w-- PLUG IN YOUR DATES
+where m.created_at =
+-- PLUG IN DETAILS ABOVE, OR DO NOT INCLUDE AT ALL
+group by n.message_status
+```
+
+- Send Success Rate
+
+```sql
+select m.send_status, count(*) from message m
+left join public."user" u
+on u.id = m.user_id
+left join campaign_contact n
+on m.campaign_contact_id = n.id
+left join campaign c
+on n.campaign_id = c.ID
+left join organization o
+on o.ID = c.organization_ID
+-- PLUG IN YOUR DATES, ORGANIZATION NAME, CAMPAIGNS, AND /OR USERS BELOW
+where m.created_at =
+and o.name=
+and c.title=
+and CONCAT(u.first_name, ' ', u.last_name)=
+-- PLUG IN DETAILS ABOVE, OR DO NOT INCLUDE AT ALL
+group by m.send_status
+```
+
+- Total Messages by Date
+
+```sql
+select c.title as Campaign, to_char(m.sent_at :: DATE, 'yyyy-mm-dd') as Sent, count(m.ID) as Messages from message m
+left join public."user" u
+on u.id = m.user_id
+left join campaign_contact n
+on m.campaign_contact_id = n.id
+left join campaign c
+on n.campaign_id = c.ID
+left join organization o
+on o.ID = c.organization_ID
+-- PLUG IN YOUR DATES, ORGANIZATION NAME, CAMPAIGNS, AND /OR USERS BELOW
+where m.created_at =
+and o.name=
+and c.title=
+and CONCAT(u.first_name, ' ', u.last_name)=
+-- PLUG IN DETAILS ABOVE, OR DO NOT INCLUDE AT ALL
+group by campaign, sent
+```
+
+- Activity by Organization
+
+```sql
+SELECT o.name as "Organization", count(*) as "Messages", count(distinct m.contact_number) as "Contacts Texted"
+FROM message m
+
+left join public."user" u
+on u.id = m.user_id
+left join campaign_contact n
+on m.campaign_contact_id = n.id
+left join campaign c
+on n.campaign_id = c.ID
+left join organization o
+on o.ID = c.organization_ID
+
+-- PLUG IN YOUR DATES, ORGANIZATION NAME, CAMPAIGNS, AND /OR USERS BELOW
+where m.created_at =
+and o.name=
+and c.title=
+and CONCAT(u.first_name, ' ', u.last_name)=
+-- PLUG IN DETAILS ABOVE, OR DO NOT INCLUDE AT ALL
+
+group by "Organization"
+order by "Messages" desc
+```
+
+- Campaign Questions
+
+
+```sql
+select distinct i.question as Questions from interaction_step i
+left join campaign c
+on c.ID = i.campaign_id
+left join campaign_contact t
+on t.campaign_id = c.ID
+left join message m
+on m.campaign_contact_id = t.ID
+left join public."user" u
+on u.id = m.user_id
+left join organization o
+on c.organization_ID = o.ID
+where i.question <> ''
+and i.question LIKE '%?'
+-- PLUG IN YOUR DATES, ORGANIZATION NAME, CAMPAIGNS, AND /OR USERS BELOW
+and m.created_at =
+and o.name=
+and c.title=
+and CONCAT(u.first_name, ' ', u.last_name)=
+-- PLUG IN DETAILS ABOVE, OR DO NOT INCLUDE AT ALL
+```
+
+- Campaigns
+
+```sql
+select o.name as Organization, c.title as Campaign, to_char(c.created_at :: DATE, 'mm/dd/yyyy') as Created, to_char(c.due_by :: DATE, 'mm/dd/yyyy') as Due from campaign c
+left join campaign_contact t
+on t.campaign_id = c.ID
+left join message m
+on m.campaign_contact_id = t.ID
+left join public."user" u
+on u.id = m.user_id
+join organization o
+on c.organization_ID = o.ID
+
+-- PLUG IN YOUR DATES, ORGANIZATION NAME, CAMPAIGNS, AND /OR USERS BELOW
+where c.created_at >=
+and c.due_by <=
+and o.name=
+and c.title=
+and CONCAT(u.first_name, ' ', u.last_name)=
+-- PLUG IN DETAILS ABOVE, OR DO NOT INCLUDE AT ALL
+
+
+group by o.name, c.title, c.created_at, c.due_by
+order by c.due_by desc, c.created_at desc
+```
+
+- Questions & Responses
+
+```sql
+select
+--n.external_ID as VANID,
+--m.contact_number as Phone,
+i.question as Question,
+q.value as Response,
+count(*)
+from message m
+left join public."user" u
+on u.id = m.user_id
+left join campaign_contact n
+on m.campaign_contact_id = n.id
+left join question_response q
+on n.id = q.campaign_contact_id
+left join interaction_step i
+on i.ID = q.interaction_step_id
+left join campaign c
+on n.campaign_id = c.ID
+left join organization o
+on o.ID = c.organization_ID
+
+where i.question is not null
+and i.question != ''
+-- PLUG IN YOUR DATES, ORGANIZATION NAME, CAMPAIGNS, AND /OR USERS BELOW
+and m.created_at =
+and o.name=
+and c.title=
+and CONCAT(u.first_name, ' ', u.last_name)=
+-- PLUG IN DETAILS ABOVE, OR DO NOT INCLUDE AT ALL
+group by 1,2
+--group by VANID, Phone, Question, Response
+```
+
+- User Roles
+
+```sql
+select u.first_name as "First Name", u.last_name as "Last Name", r.role as "Role", o.name as "Organization" from user_organization r
+join public."user" u
+on u.id = r.user_id
+join organization o
+on o.id = r.organization_id
+-- PLUG IN YOUR DATES, ORGANIZATION NAME, CAMPAIGNS, AND /OR USERS BELOW
+and o.name=
+and CONCAT(u.first_name, ' ', u.last_name)=
+-- PLUG IN DETAILS ABOVE, OR DO NOT INCLUDE AT ALL
+order by "Organization" asc, "Role" asc
+```
+
+- Admins
+
+```sql
+select u.first_name as "First Name", u.last_name as "Last Name", r.role as "Role", o.name as "Organization" from user_organization r
+join public."user" u
+on u.id = r.user_id
+join organization o
+on o.id = r.organization_id
+where r.role in ('ADMIN', 'OWNER')
+-- PLUG IN YOUR DATES, ORGANIZATION NAME, CAMPAIGNS, AND /OR USERS BELOW
+and o.name=
+and CONCAT(u.first_name, ' ', u.last_name)=
+-- PLUG IN DETAILS ABOVE, OR DO NOT INCLUDE AT ALL
+order by "Organization" asc, "Role" asc
+```
+
+- Purchased Phone Numbers
+
+```sql
+select o.name as "Organization", left(p.phone_number, 5) as "Area Code Purchased", count(*) as "Numbers Purchased", count(*)*200 as "Daily Outgoing Messages Allowed", count(*)*0.75 as "Cost"
+from owned_phone_number p
+left join organization o
+on o.id = p.organization_id
+-- PLUG IN YOUR DATES, ORGANIZATION NAME, CAMPAIGNS, AND /OR USERS BELOW
+where o.name=
+-- PLUG IN DETAILS ABOVE, OR DO NOT INCLUDE AT ALL
+group by "Organization", "Area Code Purchased"
+order by "Organization" asc, "Area Code Purchased" asc
+```
+
+- Phone Numbers by Campaign
+
+```sql
+select o.name as "Organization", c.title as "Campaign Name",
+--p.allocated_to_id as "Campaign ID",
+count(*) as "Numbers Purchased", count(*)*200 as "Daily Outgoing Messages Allowed"
+from owned_phone_number p
+left join organization o
+on o.id = p.organization_id
+left join campaign c
+on o.id = c.organization_id
+-- PLUG IN YOUR DATES, ORGANIZATION NAME, CAMPAIGNS, AND /OR USERS BELOW
+where o.name=
+-- PLUG IN DETAILS ABOVE, OR DO NOT INCLUDE AT ALL
+and p.allocated_to != 'messaging_service'
+--and [p.allocated_at = daterange]
+group by "Organization", "Campaign Name"
+order by "Organization" asc
+```
+
+- Texter Activity by Campaign
+
+```sql
+select
+CONCAT(u.first_name, ' ', u.last_name) as "Texter"
+, u.email as "Texter Email"
+,o.name as "Org"
+, c.title as "Campaign"
+, count(*) as "Outgoing Messages"
+, count(distinct m.contact_number) as "Contacts Texted"
+
+from message m
+
+
+left join public."user" u
+on u.id = m.user_id
+left join campaign_contact n
+on m.campaign_contact_id = n.id
+left join campaign c
+on n.campaign_id = c.ID
+left join organization o
+on o.ID = c.organization_ID
+
+where m.is_from_contact = false
+and u.email is not null
+-- PLUG IN YOUR DATES, ORGANIZATION NAME, CAMPAIGNS, AND /OR USERS BELOW
+and m.created_at =
+and o.name=
+and c.title=
+and CONCAT(u.first_name, ' ', u.last_name)=
+-- PLUG IN DETAILS ABOVE, OR DO NOT INCLUDE AT ALL
+
+
+group by "Org", "Campaign", "Texter", "Texter Email"
+order by "Org", "Campaign", "Contacts Texted" desc, "Outgoing Messages" desc
+```
+
+- Error Codes
+
+```sql
+select case
+ when m.error_code in (30003,3005,30006) then 'Likely Landline'
+ when m.error_code = 21611 then 'Not Enough Phone #s Purchased'
+ when m.error_code = 30007 then 'Carrier Violation'
+ when m.error_code = '-1' then 'Connection Issue'
+ else 'Other Error'
+ end as "Error Code"
+, count(*) from message m
+left join public."user" u
+on u.id = m.user_id
+left join campaign_contact n
+on m.campaign_contact_id = n.id
+left join campaign c
+on n.campaign_id = c.ID
+left join organization o
+on o.ID = c.organization_ID
+
+-- PLUG IN YOUR DATES, ORGANIZATION NAME, CAMPAIGNS, AND /OR USERS BELOW
+where m.created_at =
+and o.name=
+and c.title=
+and CONCAT(u.first_name, ' ', u.last_name)=
+-- PLUG IN DETAILS ABOVE, OR DO NOT INCLUDE AT ALL
+
+group by m.error_code
+```
+
+- Error Code Details
+
+```sql
+select
+ o.name as "Organization"
+,c.title as "Campaign"
+, case
+ when m.error_code in (30003,30005,30006) then 'Likely Landline'
+ when m.error_code = 21611 then 'Not Enough Phone #s Purchased'
+ when m.error_code = 30007 then 'Carrier Violation'
+ when m.error_code = '-1' then 'Connection Issue'
+ else 'Other Error'
+ end as "Error Code"
+--, m.error_code as "Error Code"
+, count(*)
+from message m
+
+left join public."user" u
+on u.id = m.user_id
+left join campaign_contact n
+on m.campaign_contact_id = n.id
+left join campaign c
+on n.campaign_id = c.ID
+left join organization o
+on o.ID = c.organization_ID
+
+-- PLUG IN YOUR DATES, ORGANIZATION NAME, CAMPAIGNS, AND /OR USERS BELOW
+where m.created_at =
+and o.name=
+and c.title=
+and CONCAT(u.first_name, ' ', u.last_name)=
+-- PLUG IN DETAILS ABOVE, OR DO NOT INCLUDE AT ALL
+and c.title NOT LIKE '%Test%'
+and c.title NOT LIKE '%Demo%'
+and c.title NOT LIKE 'New Campaign'
+
+group by "Organization", "Campaign", "Error Code"
+order by "Organization" asc, "Campaign", "Error Code" asc
+```
+
+- Carrier Violations
+
+```sql
+select
+ o.name as "Organization"
+,c.title as "Campaign"
+, count(*) as "Error Codes"
+from message m
+
+left join public."user" u
+on u.id = m.user_id
+left join campaign_contact n
+on m.campaign_contact_id = n.id
+left join campaign c
+on n.campaign_id = c.ID
+left join organization o
+on o.ID = c.organization_ID
+-- PLUG IN YOUR DATES, ORGANIZATION NAME, CAMPAIGNS, AND /OR USERS BELOW
+where m.created_at =
+and o.name=
+and c.title=
+and CONCAT(u.first_name, ' ', u.last_name)=
+-- PLUG IN DETAILS ABOVE, OR DO NOT INCLUDE AT ALL
+and c.title NOT LIKE '%Test%'
+and c.title NOT LIKE '%Demo%'
+and c.title NOT LIKE 'New Campaign'
+and m.error_code = 30007
+
+group by "Organization", "Campaign"
+order by "Error Codes" desc
+```
+
+- Flagged Initial Messages
-* count of contacts, texters, sent, count (and as percent of total sent) of replies, optouts and wrong numbers, for all campaigns
+
+```sql
+select
+distinct right(m.text, 120) as "Message",
+o.name as "Org",
+c.title as "Campaign"
+--,m.sent_at
+
+from message m
+
+left join public."user" u
+on u.id = m.user_id
+left join campaign_contact n
+on m.campaign_contact_id = n.id
+left join campaign c
+on n.campaign_id = c.ID
+left join organization o
+on o.ID = c.organization_ID
+-- PLUG IN YOUR DATES, ORGANIZATION NAME, CAMPAIGNS, AND /OR USERS BELOW
+where m.created_at =
+and o.name=
+and c.title=
+and CONCAT(u.first_name, ' ', u.last_name)=
+-- PLUG IN DETAILS ABOVE, OR DO NOT INCLUDE AT ALL
+and m.is_from_contact = false
+and c.title NOT LIKE '%Test%'
+and c.title NOT LIKE '%Demo%'
+and c.title NOT LIKE 'New Campaign'
+and m.error_code = '30007'
+order by "Org", "Campaign", "Message"
+```
+
+- Cost by Org
+
+```sql
+Select "Org", SUM("Cost") as "Cost" from
+
+(
+
+SELECT o.name as "Org", count(*)*0.00562 as "Cost"
+FROM message m
+left join public."user" u
+on u.id = m.user_id
+left join campaign_contact n
+on m.campaign_contact_id = n.id
+left join campaign c
+on n.campaign_id = c.ID
+left join organization o
+on o.ID = c.organization_ID
+-- PLUG IN YOUR DATES, ORGANIZATION NAME, CAMPAIGNS, AND /OR USERS BELOW
+where m.created_at =
+and o.name=
+and c.title=
+and CONCAT(u.first_name, ' ', u.last_name)=
+-- PLUG IN DETAILS ABOVE, OR DO NOT INCLUDE AT ALL
+ group by "Org"
+
+UNION ALL
+
+select o.name as "Org", count(*)*0.75 as "Cost"
+from owned_phone_number p
+left join organization o
+on o.id = p.organization_id
+-- PLUG IN YOUR ORGANIZATION NAME BELOW
+where o.name=
+-- PLUG IN DETAILS ABOVE, OR DO NOT INCLUDE AT ALL
+
+ group by "Org"
+) s
+
+group by "Org"
+order by "Cost" desc
+```
diff --git a/docs/index.html b/docs/index.html
index 9ab312fe9..5d54b3acf 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -21,5 +21,6 @@
}
+