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

Add webhooks in automation rules #455

Merged
merged 6 commits into from
Jul 23, 2024
Merged

Add webhooks in automation rules #455

merged 6 commits into from
Jul 23, 2024

Conversation

celuchmarek
Copy link
Member

@celuchmarek celuchmarek commented Jul 19, 2024

Testy dorobím, naprjv ale chcem vedieť, či je to dobre takto. V podstate som do Automation rules pridal ďalšie triggery z EventBus (message_thread_changed, message_thread_created, message_updated).

Tie webhooky vedia byť prázdny POST na zadanú URL alebo obsahujú body podľa standard-webhooks. T.j. napr:

{
  "type":"MessageThread.message_thread_changed",
  "timestamp":"2024-07-19T10:32:49.129+02:00",
  "data": {
    "message_thread_id": 251
  }
}

{
  "type":"Message.message_created",
  "timestamp":"2024-07-19T10:44:04.224+02:00",
  "data": {
    "message_id": 725,
    "message_thread_id": 251
  }
}

Autorizáciu webhookov som zatiaľ tiež neriešil, ale IMHO to zatiaľ netreba. Ale je to %lahké dorobiť - do nejakého headera pridáme podpis, prípadne jwt.

@celuchmarek celuchmarek requested a review from jsuchal July 19, 2024 10:05
app/jobs/automation/message_created_job.rb Outdated Show resolved Hide resolved
app/lib/sidebar_menu.rb Outdated Show resolved Hide resolved
app/models/automation/webhook.rb Outdated Show resolved Hide resolved
Comment on lines 48 to 61
def standard_webhook_data(thing)
if thing.instance_of?(::MessageThread)
{
message_thread_id: thing.id
}
elsif thing.instance_of?(::Message)
{
message_id: thing.id,
message_thread_id: thing.thread.id
}
else
throw StandardError.new "Unsupported webhook thing object: '#{thing.class.name}'"
end
end
Copy link
Member

Choose a reason for hiding this comment

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

Tuto chces double dispatch pripadne polymorfiu na urovni response az vo view

Copy link
Member Author

Choose a reason for hiding this comment

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

zatiaľ je všetko iba Message, takže som tieto podmienky vyhodil preč

db/migrate/20240718084836_create_automation_webhooks.rb Outdated Show resolved Hide resolved
db/migrate/20240718084836_create_automation_webhooks.rb Outdated Show resolved Hide resolved
@jsuchal
Copy link
Member

jsuchal commented Jul 22, 2024

@celuchmarek tu este dve veci mozno, co by sme rovno mohli skusit ako test toho ci to funguje dobre:

  1. overit scenar so zmenou statusu vlakna (co chce klient)
  2. ked vznikne nove vlakno u nas v ssd, tak nech to posles push a v slacku sa to nejako zobrazi - napada mi - ked je nieco na podpis, nech to prileti do slacku.

@celuchmarek
Copy link
Member Author

Snímka obrazovky 2024-07-23 o 11 21 28

@celuchmarek
Copy link
Member Author

@jsuchal updatol som podľa review a podľa dohody. Idem ešte nejaký test spraviť.


def fire!(message, event, timestamp, downloader: Faraday)
data = {
type: "#{message.class.name}.#{event}",
Copy link
Member

Choose a reason for hiding this comment

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

Tu by som mozno pridal underscore nech drzime konvencie rails/ruby

Copy link
Member Author

Choose a reason for hiding this comment

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

podľa toho štandardu má byť bodka

Copy link
Member

@jsuchal jsuchal Jul 23, 2024

Choose a reason for hiding this comment

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

to chapem, ale nazov triedy je camelcase a vsetko ostatne je underscore

Copy link
Member Author

Choose a reason for hiding this comment

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

jo, už rozumiem. Dal som .underscore

@celuchmarek celuchmarek requested a review from jsuchal July 23, 2024 10:42
Comment on lines -31 to -32
EventBus.subscribe_job :message_thread_created, Automation::MessageThreadCreatedJob
EventBus.subscribe_job :message_created, Automation::MessageCreatedJob
Copy link
Member

Choose a reason for hiding this comment

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

toto som si teraz vsimol, potencialne sa moze stat problem ked v queue budu joby ktore nevie odrazu kod spracovat (lebo uz nema ako)

Copy link
Member Author

Choose a reason for hiding this comment

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

jo, nasadíme tak, aby tam neboli.

Copy link
Member

Choose a reason for hiding this comment

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

Zvykne sa to robit na 2 fazy, naprv nasadis nove, potom ked dobehnu joby, tak nasadis fix co vyhodi joby.

Copy link
Member Author

Choose a reason for hiding this comment

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

ok, vrátil som

EventBus.subscribe_job :message_thread_created, Automation::MessageThreadCreatedJob
EventBus.subscribe_job :message_created, Automation::MessageCreatedJob
[:message_thread_created, :message_created, :message_draft_submitted].each do |event|
EventBus.subscribe_job event, Automation::EventTriggeredJob
Copy link
Member

Choose a reason for hiding this comment

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

Ked uz robime toto, tak to nazvime asi podla toho co to aj robi Automation::ApplyRulesForEventJob

Copy link
Member Author

Choose a reason for hiding this comment

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

premenoval som

@jsuchal
Copy link
Member

jsuchal commented Jul 23, 2024

@celuchmarek swagger nejaky a/alebo pouzivatelsku prirucku netreba upravit?

@celuchmarek
Copy link
Member Author

@jsuchal pridal som do swaggeru. Chceme aj do tej PDF dokumentácie?

@celuchmarek celuchmarek requested a review from jsuchal July 23, 2024 12:04
queue_as :automation
retry_on StandardError, wait: :polynomially_longer, attempts: 10

def perform(webhook, thing, event, timestamp)
Copy link
Member

Choose a reason for hiding this comment

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

tu len poznamka bokom, ze toto je primitive obsession a vlastne by v evente mal byt ten thing aj timestamp.

Copy link
Member

Choose a reason for hiding this comment

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

Ale chapem, ze nechces vyrabat serializer/deserializer kvoli tomu

Copy link
Member

@jsuchal jsuchal left a comment

Choose a reason for hiding this comment

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

Este kukni malu vec

Copy link
Member

@jsuchal jsuchal left a comment

Choose a reason for hiding this comment

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

Dokumentaciu hodme do JIRA nech sa nezabudne na to.

@celuchmarek celuchmarek merged commit 41c8a76 into main Jul 23, 2024
6 checks passed
@celuchmarek celuchmarek deleted the GO-107/push-api branch July 23, 2024 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants