Git Product home page Git Product logo

symphony-api-client-dotnet's Introduction

symphony-api-client-dotnet

Symphony API Client for .NET. This client is event based. If you are building a bot that listens to conversations, you will only have to implement an interface of a listener with the functions to handle all events that will come through the Datafeed.

Install using Package Manager

Install-Package symphony-apiclient-dotnet -Version 1.0.17	

Install using dotnet cli

dotnet add package symphony-apiclient-dotnet --version 1.0.17

Support for Symphony Elements

Elements support is added in 1.0.18, however this version of the SDK requires some code change. An example of a Program.cs is provided at the end of the README.

Configuration RSA

    {
        "sessionAuthHost": "<podname>.symphony.com",
        "sessionAuthPort": 443,
        "keyAuthHost": "<podname>.symphony.com",
        "keyAuthPort": 443,
        "podHost": "<podname>.symphony.com",
        "podPort": 443,
        "agentHost": "<podname>.symphony.com",
        "agentPort": 443,
        "sessionProxyURL": "",
        "sessionProxyUsername":"",
        "sessionProxyPassword": "",
        "botCertPath": "",
        "botCertName": "",
        "botCertPassword": "",
        "botPrivateKeyPath": "./rsa/",
        "botPrivateKeyName": "rsa-private-dotnetDemo.pem",
        "botUsername": "dotnetDemo",
        "botEmailAddress": "[email protected]",
        "appCertPath": "",
        "appCertName": "",
        "appCertPassword": "",
        "proxyURL": "",
        "proxyUsername": "",
        "proxyPassword": "",
        "authTokenRefreshPeriod": "30",
        "truststorePath": ""
    }

Configuration certificate

Create a config.json file in your project which includes the following properties

    {
      "sessionAuthHost": "COMPANYNAME-api.symphony.com",
      "sessionAuthPort": 8444,
      "keyAuthHost": "COMPANYNAME-api.symphony.com",
      "keyAuthPort": 8444,
      "podHost": "COMPANYNAME.symphony.com",
      "podPort": 443,
      "agentHost": "COMAPNYNAME.symphony.com",
      "agentPort": 443,
      "botCertPath": "PATH",
      "botCertName": "BOT-CERT-NAME",
      "botCertPassword": "BOT-PASSWORD",
      "botEmailAddress": "BOT-EMAIL-ADDRESS",
      "appCertPath": "",
      "appCertName": "",
      "appCertPassword": "",
      "proxyURL": "",
      "proxyUsername": "",
      "proxyPassword": "",
      "sessionProxyURL": "",
      "sessionProxyUsername": "",
      "sessionProxyPassword": "",
      "authTokenRefreshPeriod": "30"
    }

Proxy Settings

One Proxy

If all of the traffic to your instance of Symphony goes through a single proxy to make Pod and Session Auth calls set the folling configuration information.

      "proxyURL": "",
      "proxyUsername": "",
      "proxyPassword": "",

Two Proxies

If the traffic to your instance of Symphony is split between two proxys, one for Pod calls and a second for SessionAuth calls set the following configuration information.

Pod call proxy info:

      "proxyURL": "",
      "proxyUsername": "",
      "proxyPassword": "",

SesssionAuth proxy info:

      "sessionProxyURL": "",
      "sessionProxyUsername": "",
      "sessionProxyPassword": "",

Example Elements Program.cs

    using System;
    using System.IO;
    using System.Net;
    using System.Net.Http;
    using apiClientDotNet;
    using apiClientDotNet.Models;
    using apiClientDotNet.Authentication;
    using apiClientDotNet.Services;
    using apiClientDotNet.Listeners;
    using apiClientDotNet.Models.Events;
    using apiClientDotNet.Clients.Constants;
    using System.Collections.Generic;
    using apiClientDotNet.Utils;

    public class MyIMListener : IMListener
    {
        private SymConfig symConfig;


        public void init(SymConfig symConfig)
        {
            this.symConfig = symConfig;
        }

        override public void onIMMessage(Message message)
        {
            string FirstCommand = "";
            string SearchTerm = null;
            string SearchStatus = null;

            if (message.message.Contains("/form"))
            {
                    string fresponse = "";
                    fresponse += "<form id=\"form_id\">";
                    fresponse += "<text-field name=\"Question_Subject\" required=\"true\" placeholder=\"Ask a Question\" />";
                    fresponse += "<textarea name=\"comment\" placeholder=\"Add details (optional)\" required=\"false\"></textarea>";
                    fresponse += "<button type=\"reset\">Reset</button>";
                    fresponse += "<button name=\"submit_button\" type=\"action\">Submit</button>";
                    fresponse += "</form>";
                    sendMessage(message.stream.streamId, fresponse);
            }
        }

        private void sendMessage(String streamId, String messageText)
        {
            Console.WriteLine("streamId:" + streamId);
            OutboundMessage message = new OutboundMessage();
            message.message = "<messageML>"+messageText+"</messageML>";                
            RestRequestHandler restRequestHandler = new RestRequestHandler();
            string url = "https://" + this.symConfig.agentHost + "/agent/v4/stream/" + streamId + "/message/create";
            HttpWebResponse resp = restRequestHandler.executeRequest(message, url, false, WebRequestMethods.Http.Post, symConfig, true);

        }
    }

    public class MyElementsActionListener : ElementsActionListener
    {
            private SymConfig symConfig;

            public void init(SymConfig symConfig)
            {
                    this.symConfig = symConfig;
            }

        override public void onFormMessage(User initiator, String fstreamid, SymphonyElementsAction fform)
        {
            string Question = "";
            string comment = "";

            foreach (var item in fform.formValues)
            {
                if(item.Key == "Question_Subject"){ Question = item.Value.ToString();}
                if(item.Key == "comment") {comment = item.Value.ToString();}
            }
                    Console.WriteLine("ACTION-- Question: " + Question + " , Comment: " + comment);
        }
    }


    namespace symphony_dotnet_bot_test
    {
        class Program
        {
            private static readonly String CURRENT_DIR = Directory.GetCurrentDirectory();
            private static readonly String CONFIGFILE = CURRENT_DIR + @"/config.json";

            static void Main(string[] args)
            {
                try {
                    SymConfigLoader symConfigLoader = new SymConfigLoader();
                    SymConfig symConfig = symConfigLoader.loadFromFile(CONFIGFILE);

                    SymBotRSAAuth symAuth = new SymBotRSAAuth(symConfig);
                    symAuth.authenticate();

                    SymBotClient botClient = SymBotClient.initBot(symConfig,symAuth);

                    MyIMListener myIMListener = new MyIMListener();
                    myIMListener.init(symConfig);

                    MyElementsActionListener myElementsActionListener = new MyElementsActionListener();
                    myElementsActionListener.init(symConfig);

                    // start listening for messages
                    DatafeedEventsService dataFeedService = botClient.getDatafeedEventsService();
                    dataFeedService.addIMListener(myIMListener);
                    dataFeedService.addElementsActionListener(myElementsActionListener);
                    dataFeedService.getEventsFromDatafeed();
                }
                catch (Exception ex) {
                    Console.WriteLine(ex);
                }
            }
        }
    }

symphony-api-client-dotnet's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.