wco_models 3.1.0.297 → 3.1.0.299
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/wco/api/leads_controller.rb +5 -0
- data/app/controllers/wco/api_controller.rb +7 -0
- data/app/models/wco/ai_writer.rb +33 -0
- data/app/models/wco/tag.rb +10 -4
- data/app/models/wco_email/email_template.rb +1 -1
- data/app/models/wco_email/message.rb +3 -0
- data/app/views/wco/api/leads/by_email.jbuilder +12 -0
- data/config/routes.rb +2 -0
- data/lib/wco_models.rb +0 -1
- metadata +4 -3
- data/lib/wco/ai_writer.rb +0 -56
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 85d0f9cb5751a72aeb7b9e1c5f5e9b2c214651c32d6f72c7bf8810779ba88fc7
|
|
4
|
+
data.tar.gz: db30f4c53771bd033fa413d9031e2d852b1d390d77b7742107adb049f551a1d4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 07d605a7ec77f355862a3ec60e2f44fbc8b715de3e6d89a7f57109a1abc1cf289c79a3c4424d61316600c89e4ee95a6510c4ad923f2613cd45e73a28a4c79066
|
|
7
|
+
data.tar.gz: a8a390ed961f591d1e9cb481653252c63989b0c6820eec53da41ece91b28104a689af3091ca0dc50795b89d4263db624413077114acb7a5e37385fcdb258a855
|
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
class Wco::Api::LeadsController < Wco::ApiController
|
|
3
3
|
|
|
4
4
|
skip_before_action :decode_jwt
|
|
5
|
+
before_action :check_credentials, only: [ :by_email ]
|
|
6
|
+
|
|
7
|
+
def by_email
|
|
8
|
+
@lead = Wco::Lead.where( email: params[:email] ).first
|
|
9
|
+
end
|
|
5
10
|
|
|
6
11
|
## select2-leads-ajax
|
|
7
12
|
def index
|
|
@@ -9,6 +9,13 @@ class Wco::ApiController < ActionController::Base
|
|
|
9
9
|
##
|
|
10
10
|
private
|
|
11
11
|
|
|
12
|
+
def check_credentials
|
|
13
|
+
if params[:secret] != AWS_SES_LAMBDA_SECRET
|
|
14
|
+
render status: 400, json: { status: 400, message: "#check_credentials in wco says unauthorized." }
|
|
15
|
+
return
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
12
19
|
def decode_jwt
|
|
13
20
|
out = JWT.decode params[:jwt_token], nil, false
|
|
14
21
|
email = out[0]['email']
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
|
|
2
|
+
require "httparty"
|
|
3
|
+
|
|
4
|
+
class Wco::AiWriter
|
|
5
|
+
include ::HTTParty
|
|
6
|
+
|
|
7
|
+
base_uri "https://api.openai.com"
|
|
8
|
+
|
|
9
|
+
def self.do_call(task, content)
|
|
10
|
+
response = post(
|
|
11
|
+
"/v1/chat/completions",
|
|
12
|
+
headers: {
|
|
13
|
+
"Authorization" => "Bearer #{OPENAI_API_KEY}",
|
|
14
|
+
"Content-Type" => "application/json"
|
|
15
|
+
},
|
|
16
|
+
body: {
|
|
17
|
+
model: "gpt-4o",
|
|
18
|
+
messages: [
|
|
19
|
+
{
|
|
20
|
+
role: "system",
|
|
21
|
+
content: task
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
role: "user",
|
|
25
|
+
content: content
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
}.to_json
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
response.dig("choices", 0, "message", "content")
|
|
32
|
+
end
|
|
33
|
+
end
|
data/app/models/wco/tag.rb
CHANGED
|
@@ -35,6 +35,16 @@ class Wco::Tag
|
|
|
35
35
|
find_or_create_by({ slug: BOUNCE })
|
|
36
36
|
end
|
|
37
37
|
|
|
38
|
+
BOUNCED = 'bounced'
|
|
39
|
+
def self.bounced
|
|
40
|
+
find_or_create_by({ slug: BOUNCED })
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
DONOTSEND = 'donotsend'
|
|
44
|
+
def self.donotsend
|
|
45
|
+
find_or_create_by({ slug: DONOTSEND })
|
|
46
|
+
end
|
|
47
|
+
|
|
38
48
|
INBOX = 'inbox'
|
|
39
49
|
def self.inbox
|
|
40
50
|
find_or_create_by({ slug: INBOX })
|
|
@@ -55,10 +65,6 @@ class Wco::Tag
|
|
|
55
65
|
find_or_create_by({ slug: TRASH })
|
|
56
66
|
end
|
|
57
67
|
|
|
58
|
-
DONOTSEND = 'donotsend'
|
|
59
|
-
def self.donotsend
|
|
60
|
-
find_or_create_by({ slug: DONOTSEND })
|
|
61
|
-
end
|
|
62
68
|
|
|
63
69
|
def to_s
|
|
64
70
|
slug
|
|
@@ -137,7 +137,7 @@ class WcoEmail::EmailTemplate
|
|
|
137
137
|
|
|
138
138
|
SLUG_BLANK = 'blank'
|
|
139
139
|
def self.blank_template
|
|
140
|
-
out =
|
|
140
|
+
out = self.find_or_create_by({ slug: SLUG_BLANK })
|
|
141
141
|
end
|
|
142
142
|
def self.blank; self.blank_template; end
|
|
143
143
|
|
data/config/routes.rb
CHANGED
|
@@ -6,8 +6,10 @@ Wco::Engine.routes.draw do
|
|
|
6
6
|
|
|
7
7
|
namespace :api do
|
|
8
8
|
get 'leads', to: 'leads#index'
|
|
9
|
+
get 'leads/by-email/:email', to: 'leads#by_email', constraints: { email: /[^\/]+/ }
|
|
9
10
|
get 'leads/index_hash', to: 'leads#index_hash'
|
|
10
11
|
|
|
12
|
+
|
|
11
13
|
get 'obf', to: 'obfuscated_redirects#show' ## testing only.
|
|
12
14
|
get 'obf/:id', to: 'obfuscared_redirects#show'
|
|
13
15
|
|
data/lib/wco_models.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: wco_models
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.1.0.
|
|
4
|
+
version: 3.1.0.299
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Victor Pudeyev
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-07-
|
|
11
|
+
date: 2026-07-20 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: aws-sdk-s3
|
|
@@ -484,6 +484,7 @@ files:
|
|
|
484
484
|
- app/models/tda/option.rb
|
|
485
485
|
- app/models/tda/order.rb
|
|
486
486
|
- app/models/tda/stock.rb
|
|
487
|
+
- app/models/wco/ai_writer.rb
|
|
487
488
|
- app/models/wco/asset.rb
|
|
488
489
|
- app/models/wco/gallery.rb
|
|
489
490
|
- app/models/wco/headline.rb
|
|
@@ -544,6 +545,7 @@ files:
|
|
|
544
545
|
- app/views/wco/_search.haml
|
|
545
546
|
- app/views/wco/_select_all.haml
|
|
546
547
|
- app/views/wco/_sidebar.haml
|
|
548
|
+
- app/views/wco/api/leads/by_email.jbuilder
|
|
547
549
|
- app/views/wco/api/leads/index.jbuilder
|
|
548
550
|
- app/views/wco/api/leads/index_hash.jbuilder
|
|
549
551
|
- app/views/wco/api/tags/index.json.jbuilder
|
|
@@ -778,7 +780,6 @@ files:
|
|
|
778
780
|
- lib/tasks/migrate_tasks.rake
|
|
779
781
|
- lib/tasks/office_tasks.rake
|
|
780
782
|
- lib/tasks/wp_tasks.rake
|
|
781
|
-
- lib/wco/ai_writer.rb
|
|
782
783
|
- lib/wco/engine.rb
|
|
783
784
|
- lib/wco/facebook_poster.rb
|
|
784
785
|
- lib/wco/office_worker.rb
|
data/lib/wco/ai_writer.rb
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
# require 'httparty'
|
|
3
|
-
|
|
4
|
-
##
|
|
5
|
-
## OpenAI GPT3 GPT3.5 GPT4
|
|
6
|
-
##
|
|
7
|
-
class Wco::AiWriter
|
|
8
|
-
|
|
9
|
-
def self.run_prompt prompt
|
|
10
|
-
out = HTTParty.post("https://api.openai.com/v1/chat/completions", {
|
|
11
|
-
headers: {
|
|
12
|
-
"Content-Type": "application/json",
|
|
13
|
-
"Authorization": "Bearer #{OPENAI_API_KEY}",
|
|
14
|
-
},
|
|
15
|
-
body: {
|
|
16
|
-
model: 'gpt-3.5-turbo',
|
|
17
|
-
messages: [
|
|
18
|
-
{ role: "system", content: "You are a knowledgable office assistant." },
|
|
19
|
-
{ role: 'user', content: prompt },
|
|
20
|
-
] }.to_json
|
|
21
|
-
})
|
|
22
|
-
out = JSON.parse out.response.body
|
|
23
|
-
out.deep_symbolize_keys!
|
|
24
|
-
puts! out, 'chatgpt response'
|
|
25
|
-
out = out[:choices][0][:message][:content]
|
|
26
|
-
return out
|
|
27
|
-
end
|
|
28
|
-
def run_prompt p; self.class.run_prompt p; end
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
def self.run_headline headline
|
|
32
|
-
prompt = "Rephrase the following article title using less than 250 characters: #{headline.name}"
|
|
33
|
-
new_title = self.run_prompt prompt
|
|
34
|
-
new_title = new_title[0..255]
|
|
35
|
-
# puts! new_title, 'new_title'
|
|
36
|
-
|
|
37
|
-
prompt = "Write an article about the following topic: #{headline.name}"
|
|
38
|
-
new_body = self.run_prompt prompt
|
|
39
|
-
new_body.gsub!("\r", '')
|
|
40
|
-
new_body = new_body.split("\n\n").map { |ppp| "<p>#{ppp}</p>" }.join
|
|
41
|
-
new_body = new_body.gsub("\n", "<br />")
|
|
42
|
-
# puts! new_body[0...200], 'new_body'
|
|
43
|
-
|
|
44
|
-
report = Wco::Report.create!({
|
|
45
|
-
title: new_title,
|
|
46
|
-
# slug: new_title,
|
|
47
|
-
body: new_body,
|
|
48
|
-
author: Wco::Profile.ai_writer,
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
return report
|
|
52
|
-
end
|
|
53
|
-
def run_headline h; self.class.run_headline h; end
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
end
|