Weechat Slack



18 Nov 2018 · Comments: 0 · Tags: IRC, WeeChat, BridgeBot

Summary

In order for a community (such as the participants of an open source project) to collaborate online in real-time, a chat platform is required. Some communities have adopted multiple platforms such as IRC, Slack and Discord. Consequently a means of bridging these platforms together is required so that the users of each can converse with each other.

When working with Slack apps or Web API, you'll often need to send access tokens, also known as bearer tokens, along with inbound requests using the token query parameter. Some of the tokens you'll be given while going through the integration creation process. Other tokens you obtain by sending users through the OAuth 2.0 authentication flow.

One method of doing so is to use a bridge bot. The bot joins the community’s channel on each respective platform. Whenever a message is received, the botrelays it to all platforms other than the one it originated from.

The way in which messages from the bot are presented is dependent on the capabilities/limitations of the platform and the creativity of the bot’s admin. On IRC such messages typically contain the name of the original sender (along with other metadata) within the message text.

Send photoshop to indesign

The following excerpt illustrates an IRC channel in which a bot named Kilroy is relaying messages from the users of other platforms:

  • WeeChat official scripts This page shows a collection of WeeChat scripts written by external contributors, which can be installed directly in WeeChat with the command /script install. WeeChat developers are NOT RESPONSIBLE for problems caused by one of these scripts: you could experience problems like memory leaks, slowdowns, or even.
  • Element is the ultimate way to openly collaborate with other developers over the open Matrix network, whether they’re natively in Matrix or connected via IRC, Gitter, Slack, Discord, or elsewhere. Element is incredibly proud to support Gitter, the only developer-focused chat platform.
  • On integrating slack & other webby things. Terminal applications might be a big help here (the Windows terminal now has excellent compatibility if you’re using Windows). For instance, there’s a slack plugin for weechat (a terminal IRC / chat client) which by all accounts works pretty well.

I’ll return to this excerpt in more detail later.

Weechat Slack

The purpose of this post is to demonstrate a technique whereby the WeeChat IRC client’s scripting API can be used (with Python) to format such messages to appear as though they originate from native IRC users, thus making it easier to follow conversations.

There are other solutions available that’ll more or less achieve the same thingand may be better suited to your needs. I won’t cover these in depth but have listed a few at the end of the post under Alternative Solutions.

format_bridge_bot_output.py

The WeeChat IRC client provides a scripting API with support for several languages including Python, Perl and Ruby. Microsoft office 2016 free download for macbook pro. I had wanted an excuse to dabble with Python for quite a while, so that’s what I opted to use.

The script can be found here: format_bridge_bot_output.py.It intercepts messages before WeeChat displays them and if found to have been sent by a bridge bot proceeds to alter the message so that when displayed it has the appearance of being sent by a native IRC user.

Installation

Since this script has not been published to the WeeChat Script Repositoryit must be installed manually:

  • Download the script to Weechat’s python directory: wget -O ~/.weechat/python/format_bridge_bot_output.py https://raw.githubusercontent.com/thecliguy/WeeChat-Scripts/master/format_bridge_bot_output/format_bridge_bot_output.py
  • Create a link to the autoload directory so that the script is loaded when WeeChat starts:
    • cd ~/.weechat/python/autoload
    • ln -s ./format_bridge_bot_output.py

Configuration

Customisable non-volatile settings pertaining to a script are referred to asscript options in WeeChat terminology. Mac software to clean up my mac.

This script groups related options together, the purpose of which is to accommodate users who participate in multiple IRC channels where bridge bots areused. Each channel can have its own group of options.

The available options are:

  • <optgroup>.bot_nicks The bridge bot nick(s). Multiple nicks can be specified using a comma separated list.
  • <optgroup>.channel The channel name.
  • <optgroup>.nick_display_max_length The maximum number of characters to be displayed for nicks of non-IRC users. Those greater than the specified value are truncated with an ellipsis appended. At the time of writing, Slack permits a nick of up to 80 characters, this would dominate too much screen real estate within WeeChat, hence why it is important to impose a limit.
  • <optgroup>.regex A regular expression used to extract the following from messages relayed by the bridge bot:
    • Action: For when a user sends an action message (typically done using /me, EG /me sighs).
    • Network: The external networks bridged to IRC by the bot, EG Slack or Discord.
    • Nick: The nick of the sender (not the nick of the bot).
    • Text: The message text.
  • <optgroup>.server The internal server name used by WeeChat. To obtain a list of server names, use the WeeChat command /server list.

Please refer to the scriptfor details regarding how to add and remove script options.

Example Usage

Returning to the excerpt at the beginning of the post, we already know that thebot’s name is Kilroy and its message text is formatted as (network) <nick> Message.To expand on that, let’s suppose that the channel is called #foobar, the server is GroovyIRC and the maximum permitted nick length is 20. The options for such a channel would be as follows:

  • MyGroup.bot_nicks = Kilroy
  • MyGroup.channel = #foobar
  • MyGroup.nick_display_max_length = 20
  • MyGroup.regex = (?P<action>(?:^[x01]ACTION |^))((?P<network>(?:slack|discord))) <(?P<nick>.+?)> (?P<text>.*)
  • MyGroup.server = GroovyIRC

This is the conversation as it would appear without any modification:

This is the same conversation as it would appear using format_bridge_bot_output.py, the messages would be intercepted and amended to appear as though Barry, Charles and Nigel are native IRC users:

Alternative Solutions

These are a few alternative ways to format messages from bridge bots using the WeeChat IRC client:

  • parse_relay_msg.pl - A Perl script in the official WeeChat scriptsrepository.
  • weechat_bot2human.py - My script (format_bridge_bot_output.py) started life as weechat_bot2human.py (version 0.1.1) from the scripts repository of the TUNA (Tsinghua University TUNA Association) organization on Github. It has since been heavily modified and thus now bears little resemblance to the original script.
  • WeeChat Triggers - Run the command /help trigger for more information.

NB: I cannot personally vouch for parse_relay_msg.pl or WeeChat triggers as I have not tried them myself.

Weechat

Leaving comments has been disabled for this post.

Copyright © 2018 - 2020 thecliguy.co.uk
For details, see Licences and Copyright

There's much ado about Slack shutting down their IRC gateway. Personally I didn't even know it existed. Had I known, I would've used it.

As you might know, the desktop Slack app is built using Electron. With Electron you can build desktop apps using web technologies. This also means that they run on their own instance of Chromium, the open-source base of Google Chrome. Unfortunately this takes quite a bite out of your precious memory supply. On my Mac, with two teams in my Slack, I quickly hit 1,5GB after clicking around a bit, which is… quite a lot for what is in essence a group chat app.

Enter WeeChat. In its core, this questionable(?) sounding chat app is a highly extensible open-source command-line IRC client. There's a plugin for Slack, and it uses their WebSocket API instead of their IRC gateway. If you mainly use Slack for communicating, and are not too dependent on Slack apps, this thing should suit your needs perfectly. As a bonus: it only uses around 30-40MB of memory.

Functionality

The basics are there. You can join and chat in channels and with users, and you can edit your messages (with a s/perl/substitution/!). Obviously you can't view inline images, but for everything a link is shown. Embeds get a decent text-based preview as well. That feels very Slack-like. You can run Slack /custom commands but YMMV!

If you get mentioned or DM'ed, you get the standard Terminal alerts (red dot + sound + bounce if you configure it like that).

Installation

Adding your Slack teams is explained in the wee-slack guide, but it goes like this in the weechat interface:

By default you use the hotkeys, but WeeChat has built-in mouse support. I recommend enabling it:

Terminal lets you cmd-click links out-of the box, but after enabling mouse support, this becomes fn+cmd.

Enable emoji support:

For sending emoji yourself, I recommend Rocket.

If you want multiline support:

Plugins

Weechat Slack

I wish I could get WhatsApp and Notification Center integrations working, but I'll leave that to someone with more perseverance.

Not really a plugin, but interesting is Glowing Bear. It's a web app that can connect to WeeChat's relay gateway (which you have to enable first) over localhost. Just don't make an Electron app out of this…

Other OS'es

On Linux you should be able to install everything through your default package manager.

Weechat Slack Sign In

On Windows I recommend Ubuntu for Windows. A colleague of mine got everything working. Just make sure you add the package sources of WeeChat so you get the latest version instead of the ancient version 1.4.





Comments are closed.