Skip to content

Commit 5ffad81

Browse files
committed
Add push notification config snippets
1 parent aac6ffb commit 5ffad81

7 files changed

+138
-2
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Find your Account Sid at https://www.twilio.com/console/account/settings
2+
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
3+
// Create an API Key and Secret at https://www.twilio.com/console/chat/dev-tools/api-keys
4+
const apiKey = 'SKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
5+
const apiSecret = 'your_api_secret';
6+
// Your Chat Service SID from https://www.twilio.com/console/chat/services
7+
const serviceSid = 'ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
8+
const Twilio = require('twilio').Twilio;
9+
// Authenticate with Twilio
10+
const client = new Twilio(apiKey, apiSecret, { accountSid: accountSid });
11+
const service = client.chat.services(serviceSid);
12+
13+
// Update the service webhooks
14+
const notifications = {
15+
newMessage: {
16+
enabled: true,
17+
template: 'A New message in ${CHANNEL} from ${USER}: ${MESSAGE}',
18+
sound: 'default',
19+
},
20+
};
21+
service
22+
.update(notifications)
23+
.then(response => {
24+
console.log(response);
25+
})
26+
.catch(error => {
27+
console.log(error);
28+
});
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Download the twilio-csharp library from twilio.com/docs/libraries/csharp
2+
using System;
3+
using Twilio;
4+
using Twilio.Rest.Chat.V2;
5+
6+
class Example
7+
{
8+
static void Main (string[] args)
9+
{
10+
// Find your Account Sid at https://www.twilio.com/console/account/settings
11+
const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
12+
// Create an API Key and Secret at https://www.twilio.com/console/chat/dev-tools/api-keys
13+
const string authToken = "your_auth_token";
14+
// Your Chat Service SID from https://www.twilio.com/console/chat/services
15+
const string serviceSid = "ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
16+
17+
// Authenticate with Twilio
18+
TwilioClient.Init(accountSid, authToken);
19+
20+
// Update the service webhooks
21+
const string newMessageTemplate = "A New message in ${CHANNEL} from " +
22+
"${USER}: ${MESSAGE}";
23+
var service = ServiceResource.Update(serviceSid,
24+
notificationsNewMessageEnabled: true,
25+
notificationsNewMessageTemplate: newMessageTemplate,
26+
notificationsNewMessageSound: "default");
27+
28+
Console.WriteLine(service);
29+
}
30+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
require 'twilio-ruby'
2+
3+
# Find your Account Sid at https://www.twilio.com/console/account/settings
4+
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
5+
# Create an API Key and Secret at https://www.twilio.com/console/chat/dev-tools/api-keys
6+
api_key = 'SKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
7+
api_secret = 'your_api_secret'
8+
# Your Chat Service SID from https://www.twilio.com/console/chat/services
9+
service_sid = 'ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
10+
# Authenticate with Twilio
11+
client = Twilio::REST::Client.new(api_key, api_secret, account_sid)
12+
13+
# Update the service webhooks
14+
service = client.chat.v2.services(service_sid)
15+
.update(notifications_added_to_channel_enabled: true,
16+
notifications_added_to_channel_template: 'A New ' \
17+
'message in ${CHANNEL} from ${USER}: ${MESSAGE}',
18+
notifications_added_to_channel_sound: 'default')
19+
20+
puts "Service: #{service}"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Download the Python helper library from twilio.com/docs/python/install
2+
from twilio.rest import Client
3+
4+
# Find your Account Sid at https://www.twilio.com/console/account/settings
5+
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
6+
# Create an API Key and Secret at
7+
# https://www.twilio.com/console/chat/dev-tools/api-keys
8+
api_key = 'SKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
9+
api_secret = 'your_api_secret'
10+
# Your Chat Service SID from https://www.twilio.com/console/chat/services
11+
service_sid = 'ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
12+
13+
# Authenticate with Twilio
14+
client = Client(api_key, api_secret, account_sid)
15+
16+
# Update the service webhooks
17+
template = 'A New message in ${CHANNEL} from ${USER}: ${MESSAGE}'
18+
service = client.chat \
19+
.services("ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX") \
20+
.update(
21+
notifications_added_to_channel_enabled=True,
22+
notifications_added_to_channel_template=template,
23+
notifications_added_to_channel_sound='default')
24+
25+
print(service.sid)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.twilio;
2+
3+
// Install the Java helper library from twilio.com/docs/java/install
4+
import com.twilio.Twilio;
5+
import com.twilio.rest.chat.v2.Service;
6+
7+
public class Example {
8+
// Find your Account Sid at https://www.twilio.com/console/account/settings
9+
public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
10+
// Create an API Key and Secret at https://www.twilio.com/console/chat/dev-tools/api-keys
11+
public static final String API_KEY = "SKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
12+
public static final String API_SECRET = "your_api_secret";
13+
14+
// Your Chat Service SID from https://www.twilio.com/console/chat/services
15+
public static final String SERVICE_SID = "ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
16+
17+
public static void main(String[] args) {
18+
// Authenticate with Twilio
19+
Twilio.init(API_KEY, API_SECRET, ACCOUNT_SID);
20+
21+
// Update the service webhooks
22+
String newMessageTemplate = "A New message in ${CHANNEL} from ${USER}: " +
23+
"${MESSAGE}";
24+
Service service = Service.updater(SERVICE_SID)
25+
.setNotificationsNewMessageEnabled(true)
26+
.setNotificationsNewMessageTemplate(newMessageTemplate)
27+
.setNotificationsNewMessageSound("default")
28+
.update();
29+
30+
31+
System.out.println(service.getSid());
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
curl -X POST https://chat.twilio.com/v2/Services/{service sid} \
1+
curl -X POST https://chat.twilio.com/v2/Services/ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX \
22
-d 'Notifications.NewMessage.Enabled=true' \
33
-d 'Notifications.NewMessage.Template=A New message in ${CHANNEL} from ${USER}: ${MESSAGE}' \
44
-d 'Notifications.NewMessage.Sound=default' \
5-
-u '{twilio account sid}:{twilio auth token}'
5+
-u '{twilio account sid}:{twilio auth token}'

0 commit comments

Comments
 (0)