如何使用Logic App将Twilio中的SMS添加到Azure表存储中 [英] How do I add an SMS from Twilio into Azure Table Storage using Logic App

查看:102
本文介绍了如何使用Logic App将Twilio中的SMS添加到Azure表存储中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够通过Twilio Web Hook接收到逻辑应用程序中的文本消息. 按照以下步骤进行设置说明

关于我的问题在这里 现在,我需要将该文本添加到Azure表中. 我添加了一个解析JSON动作 我应该在内容和架构中输入什么?

我发现,如果我在内容框"内单击,则会提示我从标记中进行选择.我猜身体就是那个.

[更新] 现在,我正在尝试直接插入实体,但是我无法弄清楚如何在设计器中执行此操作. 如何展开实体"文本框以放入JSON?

[Update2]

我发现我可以通过输入Entity文本框来展开它.但是,如何插入MessageText?

[Update3]

这是我插入实体的方式

我能够在Azure存储表中获取一条记录.但是我的短信正文在哪里?

我可以看到运行有问题

我认为我需要从身体中提取一个身体,但我不知道如何

[Update4]

显示原始输入显示

{
    "host": {
        "connection": {
            "name": "/subscriptions/somenumbers/resourceGroups/mydomain.com.au/providers/Microsoft.Web/connections/azuretables"
        }
    },
    "method": "post",
    "path": "/Tables/TextMessages/entities",
    "body": {
        "Message": {
            "$content-type": "application/x-www-form-urlencoded",
            "$content": "VG9Db3VudHJ5PUFVJlRvU3RhdGU9JlNtc01lc3NhZ2VTaWQ9U000MTU4YzU1YmVkNDNjZDFiNWZmMTNiODZiNjIyNzkyNSZOdW1NZWRpYT0wJlRvQ2l0eT0mRnJvbVppcD0mU21zU2lkPVNNNDE1OGM1NWJlZDQzY2QxYjVmZjEzYjg2YjYyMjc5MjUmRnJvbVN0YXRlPSZTbXNTdGF0dXM9cmVjZWl2ZWQmRnJvbUNpdHk9JkJvZHk9VGFrZSsyJkZyb21Db3VudHJ5PUFVJlRvPSUyQjYxNDQ3NDA1NjEzJlRvWmlwPSZOdW1TZWdtZW50cz0xJk1lc3NhZ2VTaWQ9U000MTU4YzU1YmVkNDNjZDFiNWZmMTNiODZiNjIyNzkyNSZBY2NvdW50U2lkPUFDN2FhZTMxM2UwZmRlOGVkZjE5YzhjMGY5NjQ1MTgwNjYmRnJvbT0lMkI2MTQxOTU3NTQxNSZBcGlWZXJzaW9uPTIwMTAtMDQtMDE=",
            "$formdata": [
                {
                    "key": "ToCountry",
                    "value": "AU"
                },
                {
                    "key": "ToState",
                    "value": ""
                },
                {
                    "key": "SmsMessageSid",
                    "value": "SM4158c55bed43cd1b5ff13b86b6227925"
                },
                {
                    "key": "NumMedia",
                    "value": "0"
                },
                {
                    "key": "ToCity",
                    "value": ""
                },
                {
                    "key": "FromZip",
                    "value": ""
                },
                {
                    "key": "SmsSid",
                    "value": "SM4158c55bed43cd1b5ff13b86b6227925"
                },
                {
                    "key": "FromState",
                    "value": ""
                },
                {
                    "key": "SmsStatus",
                    "value": "received"
                },
                {
                    "key": "FromCity",
                    "value": ""
                },
                {
                    "key": "Body",
                    "value": "Take 2"
                },
                {
                    "key": "FromCountry",
                    "value": "AU"
                },
                {
                    "key": "To",
                    "value": "+61447405613"
                },
                {
                    "key": "ToZip",
                    "value": ""
                },
                {
                    "key": "NumSegments",
                    "value": "1"
                },
                {
                    "key": "MessageSid",
                    "value": "SM4158c55bed43cd1b5ff13b86b6227925"
                },
                {
                    "key": "AccountSid",
                    "value": "AC7aae313e0fde8edf19c8c0f964518066"
                },
                {
                    "key": "From",
                    "value": "+61419575415"
                },
                {
                    "key": "ApiVersion",
                    "value": "2010-04-01"
                }
            ]
        },
        "PartitionKey": "Twilio",
        "RowKey": "1d5a06ca-9dbd-4ba9-b514-77904710ffc3"
    }
}

[Update5]

我想我需要知道如何从@triggerBody()中获取body属性.

[Update6]

我尝试了

    "body": {
        "Message": "@triggerBody()['Body']",
        "PartitionKey": "Twilio",
        "RowKey": "@guid()"
    } 

但这会导致错误

InvalidTemplate. Unable to process template language expressions in action 'Insert_Entity' inputs at line '1' and column '1450': 'The template language expression 'triggerBody()['Body']' cannot be evaluated because property 'Body' doesn't exist. Property selection is not supported on content of type 'application/x-www-form-urlencoded'. Please see https://aka.ms/logicexpressions for usage details.'.

[Update7]

我正在更改HTTPRequest正文以使用JSON模式

"$content-type": "application/json",

代替

 "$content-type": "application/x-www-form-urlencoded",

[后记] 我这样做是因为Azure显示了警告消息 请记住在您的请求中包含一个设置为application/json的Content-Type标头".但这似乎无论哪种方法都可以.

[Update8]

使用后我能够在Azure中接收消息

消息":"@ triggerFormDataValue('Body')"

解决方案

根据该评论,我将更新答案.

如果要向Azure表插入消息,则可以通过直接输入json格式来构造表实体.更多详细信息,请参阅演示代码和屏幕截图.

注意:Azure表实体需要PartionKey和Rowkey.

{
 "Message": "@triggerFormDataValue('Body')",
 "PartitionKey": "Twilio",
 "RowKey": "@guid()"
}

I am able to receive a text message into a Logic App, via a Twilio Web Hook. as set up by following these instructions

Regarding my question here Now I need to add that text into an Azure Table. I have added a Parse JSON action What should I put in the Content and Schema?

I found that if I click inside the Content Box I am prompted to pick from a tag. I guess Body is the one.

[Update] Now I am trying to insert the Entity Directly but I cant work out how to do this in the designer. How do I expand the Entity text box so as to put the JSON in?

[Update2]

I found I could expand the Entity text box by typing in it. But how do I insert the MessageText?

[Update3]

Here is how I did the Insert Entity

I was able to get a record into the Azure storage table. But where is the body of my text message?

I can see that there was a problem running

I think I need to extract a body from the Body but I don't know how

[Update4]

Show Raw Inputs displays

{
    "host": {
        "connection": {
            "name": "/subscriptions/somenumbers/resourceGroups/mydomain.com.au/providers/Microsoft.Web/connections/azuretables"
        }
    },
    "method": "post",
    "path": "/Tables/TextMessages/entities",
    "body": {
        "Message": {
            "$content-type": "application/x-www-form-urlencoded",
            "$content": "VG9Db3VudHJ5PUFVJlRvU3RhdGU9JlNtc01lc3NhZ2VTaWQ9U000MTU4YzU1YmVkNDNjZDFiNWZmMTNiODZiNjIyNzkyNSZOdW1NZWRpYT0wJlRvQ2l0eT0mRnJvbVppcD0mU21zU2lkPVNNNDE1OGM1NWJlZDQzY2QxYjVmZjEzYjg2YjYyMjc5MjUmRnJvbVN0YXRlPSZTbXNTdGF0dXM9cmVjZWl2ZWQmRnJvbUNpdHk9JkJvZHk9VGFrZSsyJkZyb21Db3VudHJ5PUFVJlRvPSUyQjYxNDQ3NDA1NjEzJlRvWmlwPSZOdW1TZWdtZW50cz0xJk1lc3NhZ2VTaWQ9U000MTU4YzU1YmVkNDNjZDFiNWZmMTNiODZiNjIyNzkyNSZBY2NvdW50U2lkPUFDN2FhZTMxM2UwZmRlOGVkZjE5YzhjMGY5NjQ1MTgwNjYmRnJvbT0lMkI2MTQxOTU3NTQxNSZBcGlWZXJzaW9uPTIwMTAtMDQtMDE=",
            "$formdata": [
                {
                    "key": "ToCountry",
                    "value": "AU"
                },
                {
                    "key": "ToState",
                    "value": ""
                },
                {
                    "key": "SmsMessageSid",
                    "value": "SM4158c55bed43cd1b5ff13b86b6227925"
                },
                {
                    "key": "NumMedia",
                    "value": "0"
                },
                {
                    "key": "ToCity",
                    "value": ""
                },
                {
                    "key": "FromZip",
                    "value": ""
                },
                {
                    "key": "SmsSid",
                    "value": "SM4158c55bed43cd1b5ff13b86b6227925"
                },
                {
                    "key": "FromState",
                    "value": ""
                },
                {
                    "key": "SmsStatus",
                    "value": "received"
                },
                {
                    "key": "FromCity",
                    "value": ""
                },
                {
                    "key": "Body",
                    "value": "Take 2"
                },
                {
                    "key": "FromCountry",
                    "value": "AU"
                },
                {
                    "key": "To",
                    "value": "+61447405613"
                },
                {
                    "key": "ToZip",
                    "value": ""
                },
                {
                    "key": "NumSegments",
                    "value": "1"
                },
                {
                    "key": "MessageSid",
                    "value": "SM4158c55bed43cd1b5ff13b86b6227925"
                },
                {
                    "key": "AccountSid",
                    "value": "AC7aae313e0fde8edf19c8c0f964518066"
                },
                {
                    "key": "From",
                    "value": "+61419575415"
                },
                {
                    "key": "ApiVersion",
                    "value": "2010-04-01"
                }
            ]
        },
        "PartitionKey": "Twilio",
        "RowKey": "1d5a06ca-9dbd-4ba9-b514-77904710ffc3"
    }
}

[Update5]

I think I need to know how to get the body property out of @triggerBody()

[Update6]

I tried

    "body": {
        "Message": "@triggerBody()['Body']",
        "PartitionKey": "Twilio",
        "RowKey": "@guid()"
    } 

but this causes an error

ie

InvalidTemplate. Unable to process template language expressions in action 'Insert_Entity' inputs at line '1' and column '1450': 'The template language expression 'triggerBody()['Body']' cannot be evaluated because property 'Body' doesn't exist. Property selection is not supported on content of type 'application/x-www-form-urlencoded'. Please see https://aka.ms/logicexpressions for usage details.'.

[Update7]

I am changing the HTTPRequest body to use JSON Schema

"$content-type": "application/json",

instead of

 "$content-type": "application/x-www-form-urlencoded",

[Later note] I did this because Azure displayed a warning message "Remember to include a Content-Type header set to application/json in your request" However it seems to work either way.

[Update8]

I was able to receive the message in Azure when I used

"Message": "@triggerFormDataValue('Body')"

解决方案

According to the commment, I update the answer.

If we want to insert an message to Azure table, we could contruct the table entity by inputing the json format directly. More detail please refer to the demo code and screenshot.

Note :PartionKey and Rowkey is requred for Azure table entity.

{
 "Message": "@triggerFormDataValue('Body')",
 "PartitionKey": "Twilio",
 "RowKey": "@guid()"
}

这篇关于如何使用Logic App将Twilio中的SMS添加到Azure表存储中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆