-
Notifications
You must be signed in to change notification settings - Fork 76
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
Feature: add chat integration reference post #216
Conversation
This class works similar to a post but it is not a post.
add `send_chat_integration_message` scriptable that uses the rules to send a message to the chat provider add locale strings for the new scriptable update `ChatIntegrationReferencePost` `excerpt` method add tests for `ChatIntegrationReferencePost`
This makes using `trigger_notification` easier with every provider as well.
This method gets the name of the channel based on how the provider identifies it. Updates channel_name in locales yaml Adds migrate_tag_added_filter_to_all_providers.rb to move all existing rules to use Automation
Update small action locales with strings from core
@topic = context["topic"] | ||
@kind = context["kind"] | ||
@raw = context["raw"] if context["raw"].present? | ||
@full_url = (@topic.posts.empty? ? @topic.full_url : @topic.posts.first.full_url) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think maybe move this logic down into the method rather than having in intiializer
"topic_tag_changed.topic_tag_changed.added", | ||
added: tag_list_to_raw.call(added_tags), | ||
) | ||
elsif removed.present? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be removed_tags
@@ -0,0 +1,93 @@ | |||
# frozen_string_literal: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't have any rails class in a migration, it should be all sql, if we change these class, migrations are borked
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ^. You'll have to inline whatever DiscourseChatIntegration::Provider.constants
resolves to.
Update provider helper to use hashes instead of dot notation
…SQL queries Commented out migrate_tag_added_from_filter_to_automation.rb
).with_indifferent_access | ||
|
||
provider_name = channel[:provider] | ||
provider = DiscourseChatIntegration::Provider.get_by_name(provider_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think even this should be avoided, we should harcode everything in migrations
config/locales/client.en.yml
Outdated
@@ -281,3 +281,12 @@ en: | |||
label: URL | |||
channel: | |||
label: Channel | |||
|
|||
send_chat_integration_message: | |||
title: Send Chat-Integration message |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is that valid indentation here? Maybe it's github tripping
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
plugin.rb
Outdated
begin | ||
provider.trigger_notification(post, channel, nil) | ||
rescue StandardError => _ | ||
Rails.logger.error("Error while sending chat integration message") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe say it's coming from discourse automation here. It's one of the things I want to improve one day... a propre error report for automation, but meanwhile:
[discourse-automation] Error .... (automation id: x)
post = DiscourseChatIntegration::ChatIntegrationReferencePost.new(context) | ||
provider = DiscourseChatIntegration::Provider.get_by_name(provider) | ||
|
||
channel = provider.get_channel_by_name(channel_name) # user must have created a channel in /admin/plugins/chat-integration/<provider> page |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we capture a specific exception in this case and log a specific message to explain this?
plugin.rb
Outdated
provider = fields.dig("provider", "value") | ||
channel_name = fields.dig("channel_name", "value") | ||
|
||
post = DiscourseChatIntegration::ChatIntegrationReferencePost.new(context) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Im not sure we should pass the context directly here, maybe be more specific on what you pass to DiscourseChatIntegration::ChatIntegrationReferencePost.new
, the API of automation might send different things in the future
Made few comments, congrats on your understanding of automation 👏 The approach looks good to me. I can't approve because, the tricky part is the migration and I don't have the time to test this locally and more seriously. |
spec/lib/discourse_chat_integration/chat_integration_reference_post_spec.rb
Outdated
Show resolved
Hide resolved
spec/lib/discourse_chat_integration/chat_integration_reference_post_spec.rb
Outdated
Show resolved
Hide resolved
spec/lib/discourse_chat_integration/chat_integration_reference_post_spec.rb
Outdated
Show resolved
Hide resolved
lib/discourse_chat_integration/chat_integration_reference_post.rb
Outdated
Show resolved
Hide resolved
@@ -0,0 +1,93 @@ | |||
# frozen_string_literal: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ^. You'll have to inline whatever DiscourseChatIntegration::Provider.constants
resolves to.
…_post_spec.rb Co-authored-by: Jarek Radosz <[email protected]>
…_post_spec.rb Co-authored-by: Jarek Radosz <[email protected]>
…_post_spec.rb Co-authored-by: Jarek Radosz <[email protected]>
Co-authored-by: Jarek Radosz <[email protected]>
Co-authored-by: Jarek Radosz <[email protected]>
This class works similarly to a post, but it is not a post.
Before merge needs discourse/discourse#28714
This also adds
get_channel_by_name
to be used by every provider when the automation script requires it.To help out with the migration, use
get_channel_name