简体   繁体   English

C#Web API作为Jira Webhook URL

[英]c# web api as jira webhook url

I have been tasked to implement a JIRA SMS notification(using Twilio) similar to its in-built email notification. 我受命执行类似于其内置电子邮件通知的JIRA SMS通知(使用Twilio)。 I know this can be easily done using Zapier and Twilio. 我知道可以使用Zapier和Twilio轻松完成此操作。 But i am told to look for a workaround with out using Zapier. 但是我被告知要寻找一种不使用Zapier的解决方法。 The only option i think of now is to create a WebApi project that calls Twilio to send the SMS, host the WebApi project on a server and pass this URL as a WEBHOOK in JIRA. 我现在想到的唯一选择是创建一个WebApi项目,该项目调用Twilio发送SMS,将WebApi项目托管在服务器上,并将此URL作为JIRA中的WEBHOOK传递。

For this i have created a C# class library which calls Twilio. 为此,我创建了一个调用Twilio的C#类库。

class

and after that i have added a new WebApi project for this solution and added the above class project reference. 之后,我为此解决方案添加了一个新的WebApi项目,并添加了上述类项目参考。 and i have added a new controller: controller 我添加了一个新的控制器: 控制器

i am just calling the send method from the constructor with out any parameters which i think will do the job just from hardcoded number to a given number(in the controller. 我只是从构造函数中调用send方法,而没有任何参数,我认为这将完成从硬编码的数字到给定数字(在控制器中)的工作。

but what i need is to pass in messageBody and recipientPhoneNumber from the JIRA webhook to this controller. 但是我需要从JIRA webhook传递messageBody和收件人电话号码到此控制器。 Not sure how to do this. 不确定如何执行此操作。

As i am very new to WebApi's could some one please help me with the code. 因为我是WebApi的新手,所以请提供代码帮助我。 much appreciated. 非常感激。

Twilio Dev Evangelist here... Twilio Dev传播者在这里...

Mind dropping me a note at corey@twilio.com? 介意在corey@twilio.com上给我留言吗? I agree with the previous responses - this site may not be the best forum to support what you're looking for here, but I would be more than happy to directly help you out here. 我同意先前的回复-该网站可能不是支持您在此处寻找所需内容的最佳论坛,但是我很乐意直接在这里为您提供帮助。

but what i need is to pass in messageBody and recipientPhoneNumber from the JIRA >webhook to this controller. 但是我需要的是将JIRA> webhook中的messageBody和receiverPhoneNumber传递给此控制器。 Not sure how to do this. 不确定如何执行此操作。

The way webhooks work is a little bit different than your assumption above. Webhook的工作方式与上面的假设有些不同。 You cannot pass anything to JIRA webhook. 您不能将任何东西传递给JIRA webhook。 JIRA POSTs data to the webhook (your API URL). JIRA将数据发布到webhook(您的API URL)。 Once you receive the data in your API controller action, you can construct a message body and recipient phone number (from eg user object passed in by JIRA; if that object doesn't have any phone number attribute, you might have to use a custom field). 在API控制器操作中收到数据后,就可以构造消息正文和收件人电话号码(例如,通过JIRA传递的用户对象;如果该对象没有任何电话号码属性,则可能必须使用自定义领域)。

As i am very new to WebApi's could some one please help me with the code. 因为我是WebApi的新手,所以请提供代码帮助我。 much appreciated. 非常感激。

No problem. 没问题。 I guess you have done the Twilio part alright already. 我想您已经完成了Twilio部分。 Please visit MS docs to know more about Web API. 请访问MS文档以了解有关Web API的更多信息。 You have to add a controller method so that it can be called by JIRA. 您必须添加一个控制器方法,以便JIRA可以调用它。 So your final URL becomes this . 因此,您的最终到达网址为this You can then put this URL in JIRA as webhook. 然后,您可以将此URL作为webhook放在JIRA中。 Replace hostname mycompany.com by your server hostname and change other url segments based on your situation. 用您的服务器主机名替换主机名mycompany.com ,并根据您的情况更改其他URL段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM