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

feat(condo): DOMA-9613: Add recipients counter to cross-posting integrations #5026

Merged
merged 6 commits into from
Aug 12, 2024

Conversation

toplenboren
Copy link
Member

Add recipients counter to cross-posting integrations

image

Context

Context: we want to add ability to check out number of recipients before you send cross-posted news item.

Solution

I've implemented custom query that allows our partners to give their users this data. This is not a final solution, as details and architecture may be changed, (thus it is Proof of work)

How it works

  • Our partner / Open source contributor / 3rd party wants to share news to his platform of choice using Condo as UI and Backend. They already have integration working (Info on newsSharing is outside of the scope of this PR)
  • Our partner wants to give their users number of subscribers (recipients) so that users knows how many people will get his message

To do this they implement POST method called customGetRecipientsCounters (or whatever they want to call it) and put a url link to service that expose this API to newsSharingConfig

Example url: https://my-news-sharing-api/getNewsInfo

We expect that this method accepts this data:

{
  organization: {
      tin: string,
      id: string,
      name: string,
  },
  
  scopes: [{
      property: string,
      unitName: string,
      unitType: string,
  }]

  properties: [{
      id: string,
      address: string,
      addressMeta: addressMeta (JSON),
  }]
}

Condo expects output in this format:

{
  receiversCount: number
}

Note:

This method is created to support only advanced usecases with custom UI and custom Scopes logic. Integrations that do not require custom UI + custom Scopes logic (such as Telegram / Viber) would not require this logic.

More simple solution will be introduced later this year

Bonus

Sometimes you do not want preview to be shown, for example when your app does not have any preview (maybe internal system?)

Sometimes you do not want to show preview for push messages. For example, if your app sends push messages ONLY for emergency news items

I've introduced a setting in newsSharingConfig that covers this usecase

if (user.isAdmin || user.isSupport) return true

const b2bContext = await getById('B2BAppContext', b2bAppContextId)
if (!b2bContext) return false
Copy link
Contributor

Choose a reason for hiding this comment

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

Should check status and deletedAt

Copy link
Member Author

Choose a reason for hiding this comment

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

Done that

@Alllex202
Copy link
Contributor

Alllex202 commented Jul 29, 2024

This method is created to support only advanced usecases with custom UI and custom Scopes logic. Integrations that do not require custom UI + custom Scopes logic (such as Telegram / Viber) would not require this logic.

For messengers (telegram/viber), you can use number of group members as number of recipients

type: 'File',
isRequired: false,
adapter: NEWS_SHARING_FILE_ADAPTER,
},

pushNotificationSettings: {
schemaDoc: 'Push notification settings',
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
schemaDoc: 'Push notification settings',
schemaDoc: 'Push notification preferences for each B2BApp. The available options include: notifications are sent only for emergency alerts, all notifications are turned off, or all notifications are enabled',


return (
<RecipientCounterContainer
title={<>{MailingMessage}<Typography.Text strong>{buildMessageFromNewsItemScopes(newsItemScopes, intl)}</Typography.Text></>}
Copy link
Member

Choose a reason for hiding this comment

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

it looks hacky. is it possible to move inise RecipientCounterContainer or create a special component?

Copy link
Member Author

Choose a reason for hiding this comment

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

I do not see this as hacky, I think codebase would be more complex if I put this stuff inside component

Copy link
Member Author

Choose a reason for hiding this comment

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

At least not before we implement Telegram :-)

Copy link
Member

@nomerdvadcatpyat nomerdvadcatpyat left a comment

Choose a reason for hiding this comment

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

You need to remove duplicated migration and update migration number

Comment on lines 16 to 18
import { NewsItemSharingCustomRecipientCounter } from '../RecipientCounter'
import { NewsItemScopeNoInstanceType } from '../types'
Copy link
Member

Choose a reason for hiding this comment

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

use absolute imports

import { TNewsItemScopeNoInstance, TUnit } from './types'
import { NewsItemScopeNoInstanceType, TUnit } from './types'

import { Loader } from '../../common/components/Loader'
Copy link
Member

Choose a reason for hiding this comment

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

same

{
onCompleted: (data) => {
console.log(data)
console.log(get(data, ['result', 'receiversCount']))
Copy link
Member

Choose a reason for hiding this comment

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

remove console.log

@@ -0,0 +1,59 @@
// auto generated by kmigrator
// KMIGRATOR:0413_b2bappnewssharingconfig_customgetrecipientscountersurl_and_more:IyBHZW5lcmF0ZWQgYnkgRGphbmdvIDQuMi4xIG9uIDIwMjQtMDctMjggMjA6MTAKCmZyb20gZGphbmdvLmRiIGltcG9ydCBtaWdyYXRpb25zLCBtb2RlbHMKCgpjbGFzcyBNaWdyYXRpb24obWlncmF0aW9ucy5NaWdyYXRpb24pOgoKICAgIGRlcGVuZGVuY2llcyA9IFsKICAgICAgICAoJ19kamFuZ29fc2NoZW1hJywgJzA0MTJfbWFya2V0c2V0dGluZ2hpc3RvcnlyZWNvcmRfYW5kX21vcmUnKSwKICAgIF0KCiAgICBvcGVyYXRpb25zID0gWwogICAgICAgIG1pZ3JhdGlvbnMuQWRkRmllbGQoCiAgICAgICAgICAgIG1vZGVsX25hbWU9J2IyYmFwcG5ld3NzaGFyaW5nY29uZmlnJywKICAgICAgICAgICAgbmFtZT0nY3VzdG9tR2V0UmVjaXBpZW50c0NvdW50ZXJzVXJsJywKICAgICAgICAgICAgZmllbGQ9bW9kZWxzLlRleHRGaWVsZChibGFuaz1UcnVlLCBudWxsPVRydWUpLAogICAgICAgICksCiAgICAgICAgbWlncmF0aW9ucy5BZGRGaWVsZCgKICAgICAgICAgICAgbW9kZWxfbmFtZT0nYjJiYXBwbmV3c3NoYXJpbmdjb25maWcnLAogICAgICAgICAgICBuYW1lPSdwdXNoTm90aWZpY2F0aW9uU2V0dGluZ3MnLAogICAgICAgICAgICBmaWVsZD1tb2RlbHMuQ2hhckZpZWxkKGNob2ljZXM9WygnT05MWV9FTUVSR0VOQ1knLCAnT05MWV9FTUVSR0VOQ1knKSwgKCdFTkFCTEVEJywgJ0VOQUJMRUQnKSwgKCdESVNBQkxFRCcsICdESVNBQkxFRCcpXSwgZGVmYXVsdD0nRElTQUJMRUQnLCBtYXhfbGVuZ3RoPTUwKSwKICAgICAgICAgICAgcHJlc2VydmVfZGVmYXVsdD1GYWxzZSwKICAgICAgICApLAogICAgICAgIG1pZ3JhdGlvbnMuQWRkRmllbGQoCiAgICAgICAgICAgIG1vZGVsX25hbWU9J2IyYmFwcG5ld3NzaGFyaW5nY29uZmlnaGlzdG9yeXJlY29yZCcsCiAgICAgICAgICAgIG5hbWU9J2N1c3RvbUdldFJlY2lwaWVudHNDb3VudGVyc1VybCcsCiAgICAgICAgICAgIGZpZWxkPW1vZGVscy5UZXh0RmllbGQoYmxhbms9VHJ1ZSwgbnVsbD1UcnVlKSwKICAgICAgICApLAogICAgICAgIG1pZ3JhdGlvbnMuQWRkRmllbGQoCiAgICAgICAgICAgIG1vZGVsX25hbWU9J2IyYmFwcG5ld3NzaGFyaW5nY29uZmlnaGlzdG9yeXJlY29yZCcsCiAgICAgICAgICAgIG5hbWU9J3B1c2hOb3RpZmljYXRpb25TZXR0aW5ncycsCiAgICAgICAgICAgIGZpZWxkPW1vZGVscy5UZXh0RmllbGQoYmxhbms9VHJ1ZSwgbnVsbD1UcnVlKSwKICAgICAgICApLAogICAgICAgIG1pZ3JhdGlvbnMuQWx0ZXJGaWVsZCgKICAgICAgICAgICAgbW9kZWxfbmFtZT0nYjJiYXBwbmV3c3NoYXJpbmdjb25maWcnLAogICAgICAgICAgICBuYW1lPSdnZXRSZWNpcGllbnRzVXJsJywKICAgICAgICAgICAgZmllbGQ9bW9kZWxzLlRleHRGaWVsZChibGFuaz1UcnVlLCBudWxsPVRydWUpLAogICAgICAgICksCiAgICBdCg==
Copy link
Member

Choose a reason for hiding this comment

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

you need to rebase and regenerate migration to update it's number

// auto generated by kmigrator
// KMIGRATOR:0414_b2bappnewssharingconfig_customgetrecipientscountersurl_and_more:IyBHZW5lcmF0ZWQgYnkgRGphbmdvIDQuMi4xIG9uIDIwMjQtMDctMjkgMTI6MzkKCmZyb20gZGphbmdvLmRiIGltcG9ydCBtaWdyYXRpb25zLCBtb2RlbHMKCgpjbGFzcyBNaWdyYXRpb24obWlncmF0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W1vZGVscy5UZXh0RmllbGQoYmxhbms9VHJ1ZSwgbnVsbD1UcnVlKSwKICAgICAgICApLAogICAgICAgIG1pZ3JhdGlvbnMuQWRkRmllbGQoCiAgICAgICAgICAgIG1vZGVsX25hbWU9J2IyYmFwcG5ld3NzaGFyaW5nY29uZmlnaGlzdG9yeXJlY29yZCcsCiAgICAgICAgICAgIG5hbWU9J3B1c2hOb3RpZmljYXRpb25TZXR0aW5ncycsCiAgICAgICAgICAgIGZpZWxkPW1vZGVscy5UZXh0RmllbGQoYmxhbms9VHJ1ZSwgbnVsbD1UcnVlKSwKICAgICAgICApLAogICAgICAgIG1pZ3JhdGlvbnMuQWx0ZXJGaWVsZCgKICAgICAgICAgICAgbW9kZWxfbmFtZT0nYjJiYXBwbmV3c3NoYXJpbmdjb25maWcnLAogICAgICAgICAgICBuYW1lPSdnZXRSZWNpcGllbnRzVXJsJywKICAgICAgICAgICAgZmllbGQ9bW9kZWxzLlRleHRGaWVsZChibGFuaz1UcnVlLCBudWxsPVRydWUpLAogICAgICAgICksCiAgICBdCg==

exports.up = async (knex) => {
Copy link
Member

Choose a reason for hiding this comment

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

Same migration as above. You need to remove it

@toplenboren toplenboren force-pushed the toplenboren-support-news-sharing-counter-lite branch from de9fd4d to a798768 Compare August 12, 2024 11:24

return (
<RecipientCounterContainer
title={<>{MailingMessage}<Typography.Text strong>{buildMessageFromNewsItemScopes(newsItemScopes, intl)}</Typography.Text></>}
Copy link
Member Author

Choose a reason for hiding this comment

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

I do not see this as hacky, I think codebase would be more complex if I put this stuff inside component


return (
<RecipientCounterContainer
title={<>{MailingMessage}<Typography.Text strong>{buildMessageFromNewsItemScopes(newsItemScopes, intl)}</Typography.Text></>}
Copy link
Member Author

Choose a reason for hiding this comment

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

At least not before we implement Telegram :-)

apps/condo/domains/miniapp/gql.js Outdated Show resolved Hide resolved
@toplenboren toplenboren force-pushed the toplenboren-support-news-sharing-counter-lite branch from e7f128b to 7e78659 Compare August 12, 2024 11:30
Copy link

sonarcloud bot commented Aug 12, 2024

Copy link

sonarcloud bot commented Aug 12, 2024

@toplenboren toplenboren merged commit 518a785 into main Aug 12, 2024
26 checks passed
@toplenboren toplenboren deleted the toplenboren-support-news-sharing-counter-lite branch August 12, 2024 13:38
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