javascriptangulargetstream-iogetstream-chat

getStream Chat custom Message Actions


Following what their doc to add my own custom message action but didn't seem to work

import {
  StreamMessage,
  CustomMessageActionItem,
  DefaultStreamChatGenerics
} from "stream-chat-angular";

customActions: CustomMessageActionItem<DefaultStreamChatGenerics>[] = [
    {
      actionName: 'custom-action',
      actionLabelOrTranslationKey: 'Custom Action',
      actionHandler: (message: StreamMessage<DefaultStreamChatGenerics>) => {
        console.log('Custom action executed for:', message);
      },
      isVisible: (enabledActions: string[]) => {
        return enabledActions.includes('custom-action');
      },
    }
  ];

ngAfterViewInit(): void {
  this.messageActionsService.customActions$.next(this.customActions);
}


Solution

  • Resolved with the following snippet

    this.messageActionsService.customActions$.next([
          {
            actionName: 'forward',
            actionLabelOrTranslationKey: 'Forward',
            isVisible: this.isVisible,
            actionHandler: this.actionHandler,
          },
        ]);
        
      isVisible() {
        return true;
      }
    
      actionHandler() {
        /* eslint-disable-next-line no-console */
        console.log('forwarded');
      }