Невозможно выполнить привязку из CreateMessageOptions к функциям TwilioSms Azure - PullRequest
0 голосов
/ 02 декабря 2018

Следующий код:

using Microsoft.Azure.WebJobs;
using Twilio.Rest.Api.V2010.Account;
using Twilio.Types;

namespace FunctionApp2
{
    public static class Function1
    {
        [FunctionName("Function1")]
        [return: TwilioSms(AccountSidSetting = "AccountSidSetting", AuthTokenSetting = "AuthTokenSetting", From = "From")]
        public static CreateMessageOptions Run([TimerTrigger("0 */1 * * * *")]TimerInfo myTimer)
        {

            var message = new CreateMessageOptions(new PhoneNumber("XXXXX"))
            {
                Body = $"Hello thanks for your order!"
            };

            return message;
        }
    }
}

выдает ошибку:

"Microsoft.Azure.WebJobs.Host: Error indexing method 'Funct
ion1.Run'. Microsoft.Azure.WebJobs.Host: Can't bind TwilioSms to type 'Twilio.Re
st.Api.V2010.Account.CreateMessageOptions&'.

[2018-12-02 18:03:44] Error indexing method 'Function1.Run'
[2018-12-02 18:03:44] Microsoft.Azure.WebJobs.Host: Error indexing method 'Funct
ion1.Run'. Microsoft.Azure.WebJobs.Host: Can't bind TwilioSms to type 'Twilio.Re
st.Api.V2010.Account.CreateMessageOptions&'.
[2018-12-02 18:03:44] Function 'Function1.Run' failed indexing and will be disab
led.
[2018-12-02 18:03:44] No job functions found. Try making your job classes and me
thods public. If you're using binding extensions (e.g. ServiceBus, Timers, etc.)
 make sure you've called the registration method for the extension(s) in your st
artup code (e.g. config.UseServiceBus(), config.UseTimers(), etc.).
[2018-12-02 18:03:44] Host initialized (715ms)
[2018-12-02 18:03:44] Host started (743ms)
[2018-12-02 18:03:44] Job host started
[2018-12-02 18:03:44] The following 1 functions are in error:
[2018-12-02 18:03:44] Run: Microsoft.Azure.WebJobs.Host: Error indexing method '
Function1.Run'. Microsoft.Azure.WebJobs.Host: Can't bind TwilioSms to type 'Twil
io.Rest.Api.V2010.Account.CreateMessageOptions&'."

Вот зависимости:

dependencies img

Как я могу решить это?Это проблема с зависимостями или просто с кодом?

Пример взят из этой документации :

https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-twilio#example---functions-2x

1 Ответ

0 голосов
/ 03 декабря 2018

Вы создали проект функции v1, ссылаясь на пример v2.Функция v1 использует SMSMessage, а v2 использует CreateMessageOptions из-за разницы Twilio SDK.Так что просто проверьте v1 пример и измените код.

    [FunctionName("Function1")]
    [return: TwilioSms(AccountSidSetting = "TwilioAccountSid", AuthTokenSetting = "TwilioAuthToken", From = "xxx")]
    public static SMSMessage Run([TimerTrigger("0 */1 * * * *")]TimerInfo myTimer)
    {
        var message = new SMSMessage()
        {
            Body = "Hello thanks for your order!",
            To = "xxx"
        };

        return message;
    }

И проекту нужны только две зависимости Microsoft.Azure.WebJobs.Extensions.Twilio и Microsoft.NET.Sdk.Functions.

...