webhook activation is done.
when i request this url with header pass Bearer Token is given response Below .
URL : https://api.twitter.com/1.1/account_activity/all/webhooks.json
Respone :
{
“environments”: [
{
“environment_name”: “p”,
“webhooks”: [
{
“id”: “*******************",
“url”: "https:///smartTALK-webhook/Webhook/Receive”,
“valid”: true,
“created_timestamp”: “2018-10-03 08:08:55 +0000”
}
]
}
]
}
but still not received and message after webhook activation.
Please help me how to receiving new Direct messages.
this is my code in c# mvc
public ActionResult Receive()
{
GlobalObjects _GlobalObjects = new GlobalObjects();
WriteLog1.WriteInfoLog(_GlobalObjects, "Receive()", "0");
string tokensecret = ConfigurationManager.AppSettings["AccessSecret"];
string tokenkey = ConfigurationManager.AppSettings["AccessToken"];
string consumerkey = ConfigurationManager.AppSettings["ConsumerKey"];
string consumersecret = ConfigurationManager.AppSettings["ConsumerSecret"];
//return View();
var query = Request.QueryString;
WriteLog1.WriteInfoLog(_GlobalObjects, "query", query.ToString());
// _logWriter.WriteLine(Request.RawUrl);
if (query["crc_token"] != null)
{
// WriteLog1.WriteInfoLog(_GlobalObjects, "Receive()", "1");
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
// WriteLog1.WriteInfoLog(_GlobalObjects, "Receive()", "2");
byte[] keyByte = encoding.GetBytes(consumersecret);
// WriteLog1.WriteInfoLog(_GlobalObjects, "Receive()", "3");
HMACSHA256 hmacsha256 = new HMACSHA256(keyByte);
// WriteLog1.WriteInfoLog(_GlobalObjects, "Receive()", "4");
byte[] messageBytes = encoding.GetBytes(query["crc_token"]);
// WriteLog1.WriteInfoLog(_GlobalObjects, "Receive()", "5");
byte[] hashmessage = hmacsha256.ComputeHash(messageBytes);
// WriteLog1.WriteInfoLog(_GlobalObjects, "Receive()", "6");
string hashstring = Convert.ToString(hashmessage);
// WriteLog1.WriteInfoLog(_GlobalObjects, "hashstring ", hashstring.ToString());
string response_token = Convert.ToBase64String(hashmessage);
// WriteLog1.WriteInfoLog(_GlobalObjects, "response_token ", response_token.ToString());
string sha256responsetoken = "sha256=" + response_token;
//WriteLog1.WriteInfoLog(_GlobalObjects, "sha256responsetoken ", sha256responsetoken.ToString());
// StringBuilder b = new StringBuilder("\"response_token\":");
// b.Append("\"sha256=" + sha256responsetoken+"\"");
// string json = "{" +b.ToString() + "}";
string jsonData = "{\"response_token\":\"" + sha256responsetoken + "\"}";
//response _response = new response();
//_response.response_token = sha256responsetoken;
//string json = JsonConvert.SerializeObject(_response);
//dynamic data = JObject.Parse(jsonData);
return Content(jsonData, "application/json");
}
return HttpNotFound();
}
[ActionName("Receive")]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult ReceivePost(object data)
{
GlobalObjects _GlobalObjects = new GlobalObjects();
WriteLog1.WriteInfoLog(_GlobalObjects, "ReceivePost()", "");
string dataToApi = "";
try
{
// dataToApi = JsonConvert.SerializeObject(data) + ",";
}
catch (Exception ex)
{
WriteLog1.WriteErrorLog(_GlobalObjects, "ReceivePost()", " convert to string ", ex.StackTrace);
}
try
{
string ReadCEQueueName = System.Configuration.ConfigurationManager.AppSettings["SendToQueueName"].ToString();
// SmartMsmqAdeptor.MSMQAdaptor _smarttalkwebreference = new SmartMsmqAdeptor.MSMQAdaptor();
// var me = _smarttalkwebreference.SendToPrivateQueue(dataToApi, ReadCEQueueName);
}
catch (Exception ex)
{
WriteLog1.WriteErrorLog(_GlobalObjects, "ReceivePost()", " send to api ", ex.StackTrace);
}
return new HttpStatusCodeResult(HttpStatusCode.OK);
}