private void HandleMessage(string content)
        {
            RMQMessage msgContent = JsonConvert.DeserializeObject <RMQMessage>(content);
            string     toNumber;

            if (msgContent.isSendToExpert)
            {
                content = "A customer has asked you a question with following details : " + msgContent.Message +
                          " Please click here https://bit.ly/2CWbJta to answer the question!";
                toNumber = _twilloConfig.Value.ExpertNumber;
            }
            else
            {
                content = "An expert on JustAnswer responded to your question with following details : " + msgContent.Message +
                          " Please click here https://bit.ly/2CWbJta to continue chat!";
                toNumber = _twilloConfig.Value.CustomerNumber;
            }

            SendWhatsAppMessage sendWhatsApp = new SendWhatsAppMessage();

            sendWhatsApp.SendMessage(_twilloConfig.Value, new SendSmsInput()
            {
                MessageBody = content, ToNumber = toNumber
            });
            _logger.LogInformation($"consumer received {content}");
        }
示例#2
0
        public string sendSms(RMQConfig configuration, RMQMessage messageBody)
        {
            //var factory = new ConnectionFactory() { HostName = configuration.HostName, Password = configuration.Password, UserName = configuration.UserName };

            var factory = new ConnectionFactory();

            factory.Uri = new Uri(configuration.HostName.Replace("amqp://", "amqps://"));
            using (var connection = factory.CreateConnection())
                using (var model = connection.CreateModel())
                {
                    string message    = JsonConvert.SerializeObject(messageBody);
                    var    properties = model.CreateBasicProperties();

                    properties.Persistent = false;

                    // Create Exchange
                    model.ExchangeDeclare("demoExchange", ExchangeType.Direct);

                    // Create Queue
                    model.QueueDeclare("demoqueue", true, false, false, null);

                    // Bind Queue to Exchange
                    model.QueueBind("demoqueue", "demoExchange", "directexchange_key");

                    byte[] messagebuffer = Encoding.Default.GetBytes(message);
                    // Publish message to Queue
                    model.BasicPublish("demoExchange", "directexchange_key", properties, messagebuffer);

                    return(message);
                }
        }