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

Feature: add chat integration reference post #216

Merged
merged 26 commits into from
Sep 11, 2024

Conversation

Grubba27
Copy link
Contributor

@Grubba27 Grubba27 commented Aug 29, 2024

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

@Grubba27 Grubba27 changed the title Feature/add chat integration reference post Feature: add chat integration reference post Aug 29, 2024
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
@Grubba27 Grubba27 marked this pull request as ready for review September 3, 2024 20:53
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)
Copy link
Contributor

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?
Copy link
Contributor

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
Copy link
Contributor

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

Copy link
Contributor

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.

).with_indifferent_access

provider_name = channel[:provider]
provider = DiscourseChatIntegration::Provider.get_by_name(provider_name)
Copy link
Contributor

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

@@ -281,3 +281,12 @@ en:
label: URL
channel:
label: Channel

send_chat_integration_message:
title: Send Chat-Integration message
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Screenshot 2024-09-10 at 11 24 50 It took me a print to find that it was actually with weird but valid indentation

plugin.rb Outdated
begin
provider.trigger_notification(post, channel, nil)
rescue StandardError => _
Rails.logger.error("Error while sending chat integration message")
Copy link
Contributor

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
Copy link
Contributor

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)
Copy link
Contributor

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

@jjaffeux
Copy link
Contributor

jjaffeux commented Sep 9, 2024

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/integration/automation_spec.rb Outdated Show resolved Hide resolved
@@ -0,0 +1,93 @@
# frozen_string_literal: true
Copy link
Contributor

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.

@Grubba27 Grubba27 requested a review from CvX September 10, 2024 19:06
@Grubba27 Grubba27 merged commit 3f8b67d into main Sep 11, 2024
5 checks passed
@Grubba27 Grubba27 deleted the feature/add-chat-integration-reference-post branch September 11, 2024 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants