Exemplo n.º 1
0
        public async Task <HttpResponseMessage> Send(FBAgentMessageSet set)
        {
            set.SetChatbaseFields();
            MemoryStream stream            = new MemoryStream();
            DataContractJsonSerializer ser = new DataContractJsonSerializer(
                typeof(FBAgentMessageSet),
                new Type[]
            {
                typeof(FBAgentMessageCollection),
                typeof(FBAgentMessage),
                typeof(FBChatbaseFields),
                typeof(SenderID),
                typeof(RecipientID),
                typeof(FBMessageContent),
                typeof(FBAgentMessageRequestBody),
                typeof(FBAgentMessageResponseBody)
            }
                );

            ser.WriteObject(stream, set);
            stream.Position = 0;
            StreamReader  sr      = new StreamReader(stream);
            string        json    = sr.ReadToEnd();
            string        url     = String.Format(Client.BatchFBAgentMessageEndpoint, set.api_key);
            StringContent content = new StringContent(json, Encoding.UTF8, Client.ContentType);

            return(await client.PostAsync(url, content));
        }
Exemplo n.º 2
0
 public void MessagesMadeFromSetContainKeyGivenToConstructor(string key)
 {
     Chatbase.FBAgentMessageSet set = new Chatbase.FBAgentMessageSet(key);
     Chatbase.FBAgentMessage    msg = set.NewMessage();
     Assert.Equal(msg.api_key, key);
     set.Add(msg);
     Assert.Equal(set.GetMessages().Count, 1);
 }
Exemplo n.º 3
0
        public void SendingValidFBAgentMessageSetReturnsSuccess(string intent, string ver, string senderID, string recID, string msgID, string cnt)
        {
            string key = Environment.GetEnvironmentVariable("CB_TEST_API_KEY");

            if (String.IsNullOrEmpty(key))
            {
                ChatbaseClientUnitTests.PrintNoAPIKeyWarning();
            }
            else
            {
                Chatbase.FBAgentMessageSet set = new Chatbase.FBAgentMessageSet(key);
                Chatbase.FBAgentMessage    msg = set.NewMessage();

                msg.SetRecipientID(recID).SetMessageID(msgID).SetMessageContent(cnt);
                msg.intent  = intent;
                msg.version = ver;
                set.Add(msg);
                var resp = _client.Send(set).Result;
                Assert.Equal(resp.StatusCode, HttpStatusCode.OK);
            }
        }
Exemplo n.º 4
0
 public void KeyToConstructorPropagatesToInstance(string key)
 {
     Chatbase.FBAgentMessageSet set = new Chatbase.FBAgentMessageSet(key);
     Assert.Equal(set.api_key, key);
 }