Ticket article doesn't show who the message is from

Hi,
i am trying to create article in ticket based on some actions. I need internal articles from system, and external from customer, etc.


I created user Test

I create article for ticket like that.

          Ticket::Article.create(
            ticket_id:    ticket_id,
            type_id:      Ticket::Article::Type.find_by(name: 'note').id,
            sender_id:    Ticket::Article::Sender.find_by(name: 'Customer').id,
            from:         "Test <test@test.com>",
            body:         "why it doesnt work...",
            content_type: 'text/html',
            internal:     false,
          )


as you can see FROM is empty and i don’t know how to set it properly.


Also it would be nice to know how to send online notification to owner(agent) of the ticket when an internal article is sent

The from seems to be generated by the created_by or origin_by here.

customer = User.create_if_not_exists(firstname: 'hello', lastname: 'world', email: 'test2@test.com', created_by_id: 1, updated_by_id: 1)
Ticket::Article.create!(
  ticket: Ticket.find(1),
  type:      Ticket::Article::Type.find_by(name: 'note'),
  sender:    Ticket::Article::Sender.find_by(name: 'Customer'),
  body:         "why it doesnt work...",
  content_type: 'text/html',
  internal:     false,
  created_by: customer,
  updated_by: customer,
)

The from field is generated depending on the type of the article. Check the concerns for this about details:

Notification-wise I can’t really say out of the box. It depends on very much where your code is located. The notification handling is complex:

There is a TransactionDispatcher class which is gathering changes about the ticket. After the controller is handled it will commit the changes and based on that notifications are triggered. If your code is laying in a script or delayed job, then you might need to run this command afterwards:

TransactionDispatcher.commit

Hi, I’ve tried to make notifications according to your answer but I can’t figure out how to trigger the online_notification sending itself. I’ve added type_lookup to the database and online_notifcation without any problem (although I’m not sure if it’s in the right place) but I’m still not able to trigger the added notification so that the user receives it

image
these two functions are called in the function that is called by the router

  1. Does it show something if you reload F5?

  2. Did you add a activityMessage function to your models/offer.coffee ?

  3. Did you add the following concerns to your models/offer.rb ?

  include ChecksClientNotification
  include HasOnlineNotifications

and I didn’t notice that, I’m already checking (I have the rest)

Hi,
I followed your advice, and below is code that i have for now.

  • after the controller action is done, I can see that it adds my OnlineNotification for Offer object, but i do not recieve it.
  • When i click on NotificationWidget i get error ‘Cannot read properties of undefined (reading ‘toggle’)’.
  • Then when i remove my OnlineNotification from database and refresh page i can open NotificationWidget and it shows default message (No unread notifications for you. :))

app/assets/javascripts/app/controllers/_plugin/navigation.coffee

  toggleNotifications: (e) ->
    e.stopPropagation()
    console.log('toggleNotification:', @notificationWidget)
    @notificationWidget.toggle()
    @renderPersonal()
    console.log('rendertest:', @notificationWidget)
    if @notificationWidget
      @notificationWidget.remove()
    console.log('rendertest2:', @notificationWidget)
    @notificationWidget = new App.OnlineNotificationWidget()
    console.log('rendertest3:', @notificationWidget)
    @appEl.append @notificationWidget.el

When i refresh page i see console.log (rendertest, undefined), (rendertest2, undefine),( toggleNotification, undefined), but no rendertest3 at all


controllers/offer_controller.rb

          OnlineNotification.add(
            type: 'update',
            object: 'Offer',
            o_id: offer.id,
            seen: false,
            user_id: user.id,
            created_by_id: 1,
            updated_by_id: 1,
            created_at: Time.zone.now,
            updated_at: Time.zone.now,
          )
 
          TransactionDispatcher.commit

models/offer.rb

class Offer < ApplicationModel
 
  include ChecksClientNotification
  include HasOnlineNotifications
 

models/offer.coffee

  activityMessage: (item) ->
    return if !item
    return if !item.created_by
 
    switch item.type
      when 'update'
        App.i18n.translateContent('%s updated offer |%s|', item.created_by.displayName(), item.title)
      else
        "Unknow action for (#{@objectDisplayName()}/#{item.type}), extend activityMessage() of model."

I played a bit around and for me it looks like it works. I dont have your object so I tried to do it for triggers.

ubuntu-rs@ubuntu-rs:/workspace/git_zammad/zammad$ git d | cat
diff --git a/app/assets/javascripts/app/models/trigger.coffee b/app/assets/javascripts/app/models/trigger.coffee
index e4055318a0..329bff23c6 100644
--- a/app/assets/javascripts/app/models/trigger.coffee
+++ b/app/assets/javascripts/app/models/trigger.coffee
@@ -28,3 +28,14 @@ Maybe you want to set a higher priority on any ticket with the word “urgent”

 Whatever it is, you can do it with triggers: actions that watch tickets for certain changes, and then fire off whenever those changes occur.
 ''')
+
+  activityMessage: (item) ->
+    return if !item
+    return if !item.created_by
+    console.log('item', item)
+
+    switch item.type
+      when 'update'
+        App.i18n.translateContent('%s updated trigger |%s|', item.created_by.displayName(), item.objectNative.name)
+      else
+        "Unknow action for (#{@objectDisplayName()}/#{item.type}), extend activityMessage() of model."
diff --git a/app/models/trigger.rb b/app/models/trigger.rb
index 1c3cae6264..16e7708ce7 100644
--- a/app/models/trigger.rb
+++ b/app/models/trigger.rb
@@ -4,6 +4,7 @@ class Trigger < ApplicationModel
   include ChecksConditionValidation
   include ChecksHtmlSanitized
   include CanSeed
+  include ChecksClientNotification

   include Trigger::Assets
  OnlineNotification.add(
    type: 'update',
    object: 'Trigger',
    o_id: Trigger.last.id,
    seen: false,
    user_id: User.find_by(login: 'admin@example.com').id,
    created_by_id: 1,
    updated_by_id: 1,
    created_at: Time.zone.now,
    updated_at: Time.zone.now,
  )

Maybe you have to debug into your activityMessage it should get triggered there you might need to use the data in item.objectNative instead of item.