Hey guys,
Good morning!

In this post I will demonstrate how to integrate the database with the Ryver and send messages using CLR (C#), which is Slack's main competitor, in which I have already demonstrated how to do this same integration in the post SQL Server – How to integrate the database with Slack and send messages using the CLR (C#).

If you don't know or don't know how to use the CLR in SQL Server, find out how by accessing the post Introduction to SQL CLR (Common Language Runtime) in SQL Server.

What is Ryver?

For those who don't know, the Ryver is one of the most famous and used corporate communicators around the world, Slack's main competitor and aims to replace communication via email with private and public forums (within the team) focused on certain teams and/or subjects. You can create public groups, where your entire team can interact and collaborate, and private groups for each sector, where only those in the group can view the messages.

Ryver allows you to respond to emails from the tool itself, send and share files (no storage limits), send private messages and much more, all for free (there are no premium versions, no advertisements and no paid features).

Where and how can I use Ryver in my company?

This feature is especially useful for creating teams in your company and generating alerts and monitoring per team, where each team only receives alerts relating to their activities. Additionally, you can use open groups to send newsletters and notifications that are relevant to the entire company. All this, at no cost and you can receive it by email, view it on the web and on your smartphone.

Another cool way to use Ryver is to send sales target tracking to the commercial sector, so that regional and local managers can monitor the sales team's performance in real time, without having to consult and open reports, wherever they are, even outside the company.

If your company adopts Ryver, the HR department can use the service to send messages and newsletters to employees. Send Christmas messages, a special message on the employee's birthday, etc.

Anyway, the advantage of Ryver is that it can be sent in several different ways (E-mail, Web, Smartphone), wherever you are, inside or outside the company and represents a major revolution in the way people interact with information.

How to add users to Ryver

The first step to creating the integration is to create your Ryver account, accessing this link. Once created, you will receive an email to log into your account.

After creating your account, the next step is to create a user that your application or tool will use to send messages. This user must be present in all groups, otherwise it will not be possible to send messages to this group.

Ryver home screen

To add new users, click on their name in the bottom left corner and select the “Admin Settings” option.

On the screen that will open, click on the “Invite User” button and a new window will open, where you will enter the emails of the people you want to invite to your Ryver account. I recommend that you add a user exclusively for sending messages, but if you want, you can use your own username.

To create some examples, I will create a free forum and some private teams, as follows:

How to integrate database with Ryver

Once you have already created your account on Ryver and registered the user that you will use to send messages to the teams, let's get to the interesting part: Creating the .NET (C#) code that will integrate the SQL Server database with the Ryver API.

As a prerequisite to using this procedure, you will need to create the Return class, available in the post SQL Server – How to send warnings and error messages to the database using the CLR (C#) to use the method Return.Error and thus, send error messages, if they occur. You can also choose to comment the code and remove calls to this method (and also comment using Bibliotecas.Model), but I don't advise it, as you won't know when an error occurred in your call to the SP for sending messages to Ryver.

How to identify the URL:

How to identify user name:

How to identify the forum or private room ID:

How to add a user to a group:

Stored Procedure source code:

using System;
using System.Data.SqlTypes;
using System.IO;
using System.Net;
using System.Text;
using Bibliotecas.Model;

public partial class StoredProcedures
{
    [Microsoft.SqlServer.Server.SqlProcedure]
    public static void stpEnvia_Mensagem_Ryver(SqlString Ds_Tipo, SqlInt64 Nr_Time, SqlString Ds_Mensagem)
    {

        const string urlRyver = "nome_do_seu_time";
        const string usuario = "usuario_ryver";
        const string senha = "senha_ryver";
        
        var dsTipo = Ds_Tipo.Value.ToLower();
        if (dsTipo != "forums" && dsTipo != "workrooms")
            Retorno.Erro("O valor do parâmetro 'Ds_Tipo' não está entre as opções possíveis (workrooms / forums)");


        try
        {
            
            var dsScript = "{\"body\": \"" + Ds_Mensagem.Value + "\"}";

            var url = $"https://{urlRyver}.ryver.com/api/1/odata.svc/{dsTipo}({Nr_Time.Value})/Chat.PostMessage()";
            var request = (HttpWebRequest) WebRequest.Create(url);
            
            request.Method = "POST";

            var svcCredentials = Convert.ToBase64String(Encoding.UTF8.GetBytes(usuario + ":" + senha));
            request.Headers.Add("Authorization", "Basic " + svcCredentials);

            request.UserAgent = "curl/7.45.0";
            request.ContentType = "application/json";
            request.Accept = "application/json";

            var buffer = Encoding.GetEncoding("UTF-8").GetBytes(dsScript);
            using (var reqstr = request.GetRequestStream())
            {

                reqstr.Write(buffer, 0, buffer.Length);

                using (var response = request.GetResponse())
                {

                    using (var dataStream = response.GetResponseStream())
                    {

                        if (dataStream == null) return;

                        using (var reader = new StreamReader(dataStream))
                        {
                            var responseFromServer = reader.ReadToEnd();
                            Retorno.Mensagem(responseFromServer);
                        }
                    }

                }

            }

        }
        catch (Exception e)
        {
            Retorno.Erro("Erro : " + e.Message);
        }

    }

};

Usage examples for open group

-- Enviando mensagem para o grupo aberto "Grupo Livre"
EXEC CLR.dbo.stpEnvia_Mensagem_Ryver 
    @Ds_Tipo = N'forums', -- nvarchar(max)
    @Nr_Time = 1094440, -- bigint
    @Ds_Mensagem = N'Teste de Mensagem para o fórum \"Forum Livre\"' -- nvarchar(max)

Result

Usage examples for private group

-- Enviando mensagem para o grupo privado "TI"
EXEC CLR.dbo.stpEnvia_Mensagem_Ryver 
    @Ds_Tipo = N'workrooms', -- nvarchar(max)
    @Nr_Time = 1094441, -- bigint
    @Ds_Mensagem = N'Teste de Mensagem para o grupo privado \"TI\"' -- nvarchar(max)

Result

Result on Cell Phone

That's it, folks!
I hope you liked this post.
A hug and see you next time.

sql server clr .net dotnet framework c# csharp integration how to create database integration database how to send messages how to send messages notifications private group notifications dm Ryver

sql server clr .net dotnet framework c# csharp integration how to create database integration database how to send messages how to send messages notifications private group notifications dm Ryver